Access modifiers inside a private static nested class in Java

前端 未结 2 1729
清酒与你
清酒与你 2021-01-12 03:54

I have a \"private static\" nested class in Java. What is the significance of access modifiers for fields and methods inside this class? I\'ve tried both public and private

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-12 04:33

    Two kinds of nested classes: 1. Static (nested class) and 2. Non-static (also called inner class)

    Now, the Outer class, MyList can access all the members of the inner class Node, but you actually use the access specifiers for the members of the class Node (nested class) when you want restrictions of some external class accessing it.

    Interesting reads: Source1, Source2

提交回复
热议问题