Sunday, April 10, 2016

JAVA Access Modifiers


The following table shows the access to members permitted by each modifier from higher precedence to lower.

Access Levels
ModifierClassPackageSubclassWorld
publicYYYY
protectedYYYN
no modifierYYNN
privateYNNN


Let's look at a collection of classes and see how access levels affect visibility. The following figure shows the four classes in this example and how they are related
.
Classes and Packages of the Example Used to Illustrate Access Levels
Classes and Packages of the Example Used to Illustrate Access Levels

The following table shows where the members of the Alpha class are visible for each of the access modifiers that can be applied to them.
Visibility
ModifierAlphaBetaAlphasubGamma
publicYYYY
protectedYYYN
no modifierYYNN
privateYNNN

1 comment: