Why can I access the private members of an enclosing class reference

前端 未结 3 1694
有刺的猬
有刺的猬 2021-01-19 18:42

I have seen many questions about accessing private members of an enclosing class. However, my question is the opposite.

If I have (as an example), the following cod

3条回答
  •  有刺的猬
    2021-01-19 19:07

    static methods of a class can access private members of the same class through the same class instance. This behavior is consistent for static classes as well.

    static void b(A someA) {
        String b = someA.outerString;
    }
    

提交回复
热议问题