首页 > 数据库技术 > 详细

Controlling Access in Java

时间:2015-11-07 06:38:49      阅读:298      评论:0      收藏:0      [点我收藏+]

Referrence: Oracle Java Doc

Two levels

top level: public, or package-private (no explicit modifier)

member level: public, private, protected, package-private (no explicit modifier)

Three Modifiers & Four Access Control Types

1. public

A class/ member may be declared with the modifier public, in which case that class is visible to all classes everywhere.

2. package-private (no explicit modifier)

If a class/ member has no modifier (the default, also known as package-private), it is visible only within its own package.

3. private

The private modifier specifies that the member can only be accessed in its own class. 

4. protected

The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.

Access Levels Chart

技术分享

1st col: Whether the class itself has access to the member defined by the access level.

2nd col: Whether classes in the same package as the class (regardless of their parentage) have access to the member.

3rd col: Whether subclasses of the class declared outside this package have access to the member.

4th col: Whether all classes have access to the member.

 

Controlling Access in Java

原文:http://www.cnblogs.com/ireneyanglan/p/4944258.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!