Hello,
See the following code:
public class Superclass {
public static void main(
String[] args) {
System.out.println(new Subclass().methodA());
}
Superclass() {
System.out.println("SuperClass Constructor Executed");
}
private int methodB() {
System.out.println("methodB in Superclass");
return 9;
}
int methodA() {
System.out.println("methodA in Superclass");
return methodB();
}
}
class Subclass extends Superclass
{
Subclass()
{
System.out.println("SubClass Constructor Executed");
}
/*protected int methodB()
{
System.out.println("methodB in Subclass");
return 1;
}*/
}
and check the result:
SuperClass Constructor Executed
SubClass Constructor Executed
methodA in Superclass
methodB in Superclass
9
How the private method B is visible from the Subclass?
I just do not see the logic, what do I miss?
Thanks,
..Cristian