四种权限修饰符整理

  • 范围排序
    public > protected > (default) > private
public protected (default) private
同一个类(我自己) 可以 可以 可以 可以
同一个包(我邻居) 可以 可以 可以 不可以
不同包子类(我儿子) 可以 可以 不可以 不可以
不同包非子类(陌生人) 可以 不可以 不可以 不可以

猜你喜欢

转载自blog.csdn.net/weixin_41121063/article/details/88043168