Hello,
What are the different types of access modifiers in JAVA?
Hello,
What are the different types of access modifiers in JAVA?
Java Access Modifiers (also known as Visibility Modifiers) regulate access to classes, fields and methods in Java. These modifiers determine whether a field or method in a class, can be used or invoked by another method in another class or sub-class. Access modifiers can be used to
restrict access, and therefore functionality, to certain classes and methods; often to enhance data integrity and prevent unauthorized alteration or execution of fields and methods of the particular object. Access modifiers are an integral part of object-oriented programming.
Thus, in summary, properties of Access modifiers:
- regulate access to classes, fields and methods
- can restrict access to certain classes and methods
- they are the integral part of object-oriented programming
In Java, access modifiers are declared with the class, method or field.
Private : It can access with in the class only
public : It can Access Any where
protected : It can access with in the package and sub class of the package also
default : it access with in the package only.
- Default Access
- The package Access Modifier
- The protected Access Modifier
- The public Access Modifier
- The public-read Access Modifier
- The public-init Access Modifier
http://java.sun.com/javafx/1/tutorials/core/modifiers/
If a class has public visibility, the class can be referenced by anywhere in the program. If a class has package visibility, the class can be referenced only in the package where the class is defined. If a class has private visibility, (it can happen only if the class is defined nested in an other class) the class can be accessed only in the outer class... keywords that help set the visibility and accessibility of a class, its member variables, and methods.
If a variable is defined in a public class and it has public visibility, the variable can be reference anywhere in the application through the class it is defined in. If a variable has package visibility, the variable can be referenced only in the same package through the class it is defined in. If a variable has private visibility, the variable can be accessed only in the class it is defined in.
If a method is defined in a public class and it has public visibility, the method can be called anywhere in the application through the class it is defined in. If a method has package visibility, the method can be called only in the same package through the class it is defined in. If a method has private visibility, the method can be called only in the class it is defined in.
Bookmarks