Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Beginner
Jun 4, 2001

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(
Navneet Gupta
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap