Child class accesses the protected variables through inheritance, not accessing it through a reference to an instance of the superclass. : protected « Modifiers « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Modifiers » protected 
3.5.3.Child class accesses the protected variables through inheritance, not accessing it through a reference to an instance of the superclass.
package certification;
public class Parent {
   protected int x = 9// protected access
}


package other;
import certification.Parent;
class Child extends Parent {
   public void testIt() {
      System.out.println("x is " + x)// Child inherits x
      Parent p = new Parent()
      System.out.println("X in parent is " + p.x)// Compiler error!
   }
}
3.5.protected
3.5.1.protected features are even more accessible than default features.
3.5.2.Let's take a look at a protected instance variable of a superclass.
3.5.3.Child class accesses the protected variables through inheritance, not accessing it through a reference to an instance of the superclass.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.