Protected access modifier in Java

后端 未结 4 1961
温柔的废话
温柔的废话 2020-11-30 07:56

I am having a little trouble understanding the protected access modifier in java (or the design behind it). I thought it meant package access and access through objects that

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 08:50

    Protected member in java

    Same package-(it behaves like default)

    It is accessible with in the sameclass,its child classes and also non child classes.(it behaves like default) You can even access protected members using parent or child reference.

    Outside package-

    It is accessible only to itz child class and the most important point here is that reference used must be of the same child class only

提交回复
热议问题