Please have a look at following code.
class TestClass{
private void privMethod()
{
System.out.println("TestClass Method");
}
public static void main(String... args)
{
TestClass obj=new SubClass();
obj.privMethod();
}
}
class SubClass extends TestClass
{
private void privMethod()
{
System.out.println("SubClass Method");
}
}
when I compile this code its gets compiled fine. when I run TestClass, the output is: TestClass method The ref. variable obj is of TestClass type but it is referring to a Sub class' object so at run time it should bind with Sub's privMethod(). Can you explain this?