java 子类访问父类私有成员_关于java:如果两个类都在同一个包中,子类是否可以访问父类私有成员...

我正在读一个Java文档,上面写着

A subclass inherits all of the public and protected members of its

parent, no matter what package the subclass is in. If the subclass is

in the same package as its parent, it also inherits the

package-private members of the parent. You can use the inherited

members as is, replace them, hide them, or supplement them with new

members

它表示如果子类位于同一个包中,则子类可以访问父类的私有成员。我已经尝试过了,我无法访问子类中父类的私有成员

它说package-private不是private。

不,它表示

If the subclass is in the same package as its parent, it also inherits the package-private members of the parent

package-private(无修饰语)与private修饰语(private修饰语)不同。有关差异,请参阅https://docs.oracle.com/javase/tutorial/java/javaoo/accesscontrol.html。

package-private和private成员之间存在差异。除了类本身,任何人都不能访问私有成员。但是,软件包私有成员是那些仅属于该特定软件包的private成员,并且该特定软件包中的任何成员都可以访问这些成员。

0305a9292c702fdaa91d9111cd11bab0.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值