I was told that inheritance is runtime, but I want to ask that if inheritance is runtime, how does the compiler generate an error at compile time when we try to access the data member of the parent class through the object of the child class:
class PrivateData {
private int x = 50;
void show() {
System.out.println(x);
}
}
class ChildPrivateData extends PrivateData {
public static void main(String s[]) {
ChildPrivateData c1 = new ChildPrivateData();
System.out.println(c1.x);
}
}
source
share