Master java skills

Access Modifiers In Java

Access modifier also known as Access specifier defines the visibility of a variable or a method. Following four types of access modifiers are there:

default : default means when we do not specify any access modifier. Default members are accessible only within the same package

private : private members of a class are accessible only within the class. It has the least visibility.

protected : protected members are accessible in the same package and all the subclasses whether in the same package or different package

public : public members are accessible from everywhere meaning from all the classes in and from other packages.It has the maximum visibility

Access ModifierWithin ClassWithin PackageOutside Package but only subclassesOutside Package
defaultYesYesNoNo
privateYesNoNoNo
protectedYesYesYesNo
publicYesYesYesYes