Public, Private, Protected, and default identifiers

本文详细解释了私有(private)、受保护(protected)和公共(public)等访问修饰符的作用范围。私有成员只能在类内部访问;受保护成员允许在类及其子类中访问;而公共成员则可以在任何地方访问。没有指定访问修饰符的成员默认为包级可见,即仅在同一包内的类可以访问。

Private methods/properties (priviate int a;) can’t be accessed from outside of the class.
Protected (protected int a;)can be accessed in the class or from its sub-class.
Public (public int a;)can be accessed from any places.
The methods/properties without any identifier (int a) can be access by the classes within the same package; but can’t be accessed out of the package.

In a class, all identifiers can access each other. So in fact “identifier” is for “external” access.

转载于:https://www.cnblogs.com/backpacker/archive/2011/12/01/2271188.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值