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

前端 未结 3 1729
有刺的猬
有刺的猬 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 18:59

    B is a member of A and therefore has access to A's private fields and methods.
    In this case, although B is static it is using an instance of A to access the field A.outerString.

提交回复
热议问题