Why protected can be access in same Package without inheritance in java? [duplicate]

守給你的承諾、 提交于 2019-11-30 11:32:24

Why? Because that's how the Java programming language was designed. There's not much more to it.

Something that is protected is accessible from

  • the class itself,
  • classes in the same package (doesn't matter if they are subclasses or not),
  • subclasses (doesn't matter if they are in the same package or not).

This is different from C++, but Java is not C++, so it doesn't necessarily work in the same way.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!