In given program assume
class Base {
private void show() {
System.out.println("Base");
}
public void add() {
show();
}
}
class Child extends Base {
public static void main(String... s) {
Child c = new Child();
c.add();
}
}
here add()
is directly accessible in child & through which we are accessing the private member function show()
of Base
class. Here there is only 1 JVM instance i.e of Child
class and since private member are not inherited they are not in JVM instance of Child
and JVM instance of Base
does not exist (so that linking between them can be done).
Hence it is proves that they are inherited in child class!!! please explain this.