Compiling and running this code prints: From SuperTest
Q. Can someone please explain why it prints "From SuperTest" and not "From SubTest" since the inherited instance method printa() is invoked on subclass reference type which I think should be considered for invoking the "redefined / redeclared" static method defined in the subclass??
Think of it like this... the printa() method is being run from SuperTest and thereby calls the super method. Override this method in the sub class and the result will be different.
Once you over ride the method printa() , the method a() in the sub class will get called from the subclass version of printa() . Else the method in the super class is called. So when the method is over ridden it prints "From SubTest".
In SuperTest class, compiler will hader code "void printa() { a(); }" to "void printa() { SuperTest.a(); }" See Ernest's post in this thread. [ May 21, 2006: Message edited by: wise owen ]