The Protected Modifier

The Protected Modifier

A protected feature of a class is available to all classes in the same package, just like a friendly feature. Moreover, a protected feature is available to all subclasses of the class that own the protected feature. This access is provided even to subclasses that reside in a different package than the class that owns the protected feature.
Let’s look at how the protected specifier affects access for classes in the same package. Consider a class Alpha, which is declared to be within a package named Greek and which includes one protected member variable and one protected method declared:

 package Greek;class Alpha {    protected int iamprotected;    protected void protectedMethod() {        System.out.println(


Share the Post: