Access control of java - from complete reference Java
来源:互联网 发布:sql增加语句 编辑:程序博客网 时间:2024/04/29 10:57
As you know, encapsulation links data with the code that manipulates it. However, encapsulation provides another important attribute: access control. Through encapsulation, you can control what parts of a program can access the members of a class. By controlling access, you can prevent misuse. For example, allowing access to data only through a well-defined set of methods, you can prevent the misuse of that data. Thus, when correctly implemented, a class creates a "black box" which may be used, but the inner workings of which are not open to tampering.
How a member can be accessed is determined by the access specifier that modifies its declaration. Java supplies a rich set of access specifiers. Some aspects of access control are related mostly to inheritance or packages.
Java's access specifiers are public, private and protected. Java also defines a default access level. protected applies only when inheritance is involved. So with the public and private, when a member of a class is modified by the public specifier, then that member can be accessed by any other code. When a member of a class is specified as private, then that member can only be accessed by other members of its class. Now you can understand why main() has always been preceded by the public specifier. It is called by code that is outside the program----that is, by the Java run-time system. When no access specifier is used, then by default the member of a class is public within its own package, but can't be accessed outside of its package.
Usually, you will want to restrict access to the data members of a class----allowing access only through methods. Although methods will usually provide access to the data defined by a class, this does not always have to be the case. It is perfectly proper to allow an instance variable to be public when there is good reason to do so.
- Access control of java - from complete reference Java
- Control Statements of Java -from The Complete Reference Java
- Static and Final of Java-from complete reference of Java
- new operation in java - from the complete reference Java
- why java does not support or allow pointers - from the complete reference java
- 处理教材:Access Control of "Thinking in Java"
- Java 2: The Complete Reference, Fifth Edition
- Java 2: The Complete Reference, Third Edition
- 《Java: The Complete Reference》等书读书笔记
- Microsoft Office Access 2003: The Complete Reference
- Microsoft Office Access 2007: The Complete Reference
- Think In Java 笔记2 Access control
- Java学习笔记:图解Access Control Modifier
- Control browsers from you java application
- Pay Attention to the Reference of Java
- JAVA访问权限控制(JAVA Access Control)
- 反向控制-Inversion of Control(JAVA Application)
- Elements of ArrayList of java, cloned, not reference
- ASP开发规范
- 地图图层所应包含的数据表(建议)
- fork和defunct(僵尸)进程
- 期刊
- 夏日如水
- Access control of java - from complete reference Java
- 模仿MSN消息提示的效果
- 新闻中显示上一篇下一篇
- 长期用电脑人士要多吃樱桃
- 用1000块组装笔记本的全过程 强。
- 分组菜单
- SQL 注入天书 - ASP 注入漏洞全接触
- 经济博士国外学习感想
- 上传加水印