Hi Armel et al.,
First you have wrongly used code tags, they must be in square brackets and not angle brackets.
Ok lets try to answer your question now.
Parent class has couple of methods method1() and method2(). method1() is private and hence it will not be inherited by subclasses and method2() since its not marked private it will be inherited by subclass and can be overriden by subclass. Here you have chosen not to override method2() in Test class. Now you have defined method1() in Test class, Because method1() is not inherited by Test class this method1() is jst a new method in your class and is not a legal override of method1() defined in Parent class.
In the example method1() is not inherited by subclass Test, but method2() is inherited by Test.
Parent p = new Test();
You create a Parent reference and assign a subclass object Test.
p.method2(); First you can access method2() from Test class because its not marked private and hence its inherited by Test class.Since you are not overriding method2() , method2() of Parent class is invoked. Within method2() of parent class you invoke method1() and since method1() is not inherited by Test class [because its marked private and therefore cannot be overriden] method1() of Parent class is invoked.
Modify Parent.method1() to public. and you will observe the results Or you can override method2() in your subclass and you will observe the result.
If a method() is inherited by subclass then invocation of method() from Parent class invokes method() of subclass at runtime if its not inherited and not defined in the class from which you are invoking it you will get a compiler error.
If a method is not inherited by subclass then invocation of method() from Parent class will invoke method() of Parent class provided its defined in Parent class.