JAVA ACCESS
MODIFIERS
What is access modifier ?
In Java, access modifiers are used to set the accessibility (visibility) of classes, interfaces,
variables, methods, constructors, data members, and the setter methods.
class Animal {
public void method1() {...}
private void method2() {...}
}
Types of Access Modifier
Modifier Description
declarations are visible only within the
Default
package (package private)
Private declarations are visible within the class only
declarations are visible within the package or
Protected
all subclasses
Public declarations are visible everywhere