I couldn't understand properly the ans to this quest.
class Parent
{
private void method1()
{
System.out.println("Parent's method1()");
}
public void method2()
{
System.out.println("Parent's method2()");
method1();
}
}
class Child extends Parent
{
public void method1()
{
System.out.println("Child's method1()");
}
public static void main(
String args[])
{
Parent p = new Child();
p.method2();
}
}
Ans o/p is
Parent's method2();
Parent's method1();
I understand that private methods are not inherited and not overridden. Still i was expecting "Child's method1()" to be printed. When p.method2()(then inheritted method2)is called, a this pointer is passed which points to Child's object. Child doesn't know anything about the super classes method1(), but then the ans......I think I am making a blunder somewhere. Pls help me in this.
Also if u could give some link on this...