If i am not wrong,The method which is overridden is not said to be inherited. Please check the code, here static init() is hidden
As we know static methods are resolved during compile time and a static method call is done according to type of reference, Here type of override is OverrideStatic, so on calling override.init(). the hidden static init() method of OverrideStatic class is called.This is clear to me. Now when we call override.local();, the call is resolved by dynamic binding and the local() of class A is called, which will futher contain call to init() and hi(), Now i know that hi() of Override class is called, but why init() of Override is not called, as Type of original override reference is OverrideStatic and init() is also hidden in class Overriden.
In summary i need clerification on call of init() in side local() method of class A. Which init() will be call and Why ???
( tags added so that mere mortals can read it) [ June 16, 2005: Message edited by: Barry Gaunt ]
when local() is called, this(reference) is available to local(). and with the help of this(reference) only non static function will be called(remember this(reference) is pointing to object of OverrideStatic class)... since init() is static and superclass doesnot know about subclass so A's init willbe called.
if we provide overriiden local in OverrideStatic class then OverrideStatic's init() will be called..
if i am wrong plz correct me... [ June 14, 2005: Message edited by: rajan singh ]
you are right...using reference of base type we can invoke the method of subclass if it is overridden in sub class otherwise not. and since method1() is private we are not overriding it....even if invoke method1() using base class reference(though it is pointing to base class) it will not complile because the using base class reference(pointing to subclass object) only overriden method is called.