8 A Access Protection in Java Packages
8 A Access Protection in Java Packages
(../index.html)
In java, the access modifiers define the accessibility of the class and its members. For example,
private members are accessible within the same class members only. Java has four access
In java, the package is a container of classes, sub-classes, interfaces, and sub-packages. The
class acts as a container of data and methods. So, the access modifier decides the accessibility of
In java, the accessibility of the members of a class or interface depends on its access specifiers.
The following table provides information about the visibility of both data members and methods.
www.btechsmartclass.com/java/java-access-protection-in-packages.html 1/4
9/1/2021 Java Tutorials - Access protection in java packages
🔔 The private members can be accessed only inside the same class.
🔔 The protected members are accessible to every child class (same package or other
packages).
🔔 The default members are accessible within the same package but not outside the
package.
www.btechsmartclass.com/java/java-access-protection-in-packages.html 2/4
9/1/2021 Java Tutorials - Access protection in java packages
class ParentClass{
int a = 10;
void showData() {
System.out.println("Inside ParentClass");
void accessData() {
System.out.println("Inside ChildClass");
obj.showData();
obj.accessData();
www.btechsmartclass.com/java/java-access-protection-in-packages.html 3/4
9/1/2021 Java Tutorials - Access protection in java packages
Previous (java-defining-packages.html)
Next (java-importing-packages.html)
www.btechsmartclass.com/java/java-access-protection-in-packages.html 4/4