Why this code runs fine??
package certification;
public class Parent {
protected int x = 9; // protected access
protected void z(){System.out.println(5);}
}
package other;
import certification.Parent;
class C extends Parent{}
public class Child extends C {
public void testIt() {
System.out.println("x is " + x);
this.z();
}
}
import other.Child;
class Test extends Child{
public static void main(String args[]){
new Child().testIt();
}
}
This gives output:
x is 9
5
But how can subclass(Child)
of subclass(C)
can access protected member of class Parent.