Child class accesses the protected variables through inheritance, not accessing it through a reference to an instance of the superclass. : protected « Modifiers « SCJP
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!
}
}