java修饰符访问范围,Java访问修饰符的可访问范围

Java has private, protected, and public access modifiers. Can you explain the accessibility scope of these modifiers.

How can I access a protected member within a different package?

解决方案

For better understanding you need to see this

Access Modifiers

Same Class Same Package Subclass Other packages

public Y Y Y Y

protected Y Y Y N

no access modifier Y Y N N

private Y N N N

Here the important difference is between Default and protected.

Default: Never accessible outside the package

Protected: Only accessible outside the package, if and only if the class is a subclass

Please see this for further details.

Edit: As your question's answer is also the same that You can access the protected member by make your class a sub class of the class , in which protected member is defined

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值