Java Visibility of Variables and Methods
- One of the most important aspects of object-oriented design is data hiding, or encapsulation.
Basic Access Modifiers:
- Without access modifier (default), the variables and methods of a class are accessible to members of the class itself and to other classes in the same package.
- Methods and variables (members) declared with a private modifier are accessible only within their class.
- Members declared with a public modifier are accessible from any class in any package.
- Members declared with a protected modifier are accessible by other classes in the package and sub-classes inside or outside the package.
Private, default, protected, and public visibility illustration:
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the
correctness in the pages or source codes.
The risk of using this web-site pages or any program
codes from this website is entirely at the individual user.