The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
July 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

It's you. not Java

Posted by Kishori Sharan on July 21, 2001 at 10:15 PM

"Is it Java or me that is being stupid here :-)." ***It is you not Java.*** Never mind, I am just kidding. Here is the explanation. The concept of inheritance applies only to object methods i.e. non-static methods. If you define a static method in descendent class, which has already been defined in ancestor class then this is known as method hiding and not method overriding. So in case of static methods calls dynamic binding dosn't apply. For all static method call it is decided at compile time itself that which method will be called. For example,
Ancestor a ;
....
a.m1() ;

Here, a is an object of class Ancetor and m1() is a static method defined in Ancestor class. Then even if at run time the object reference a contains the reference of any descendent class of Ancetor a.m1() will always call m1() static method in Ancestor class and not of any descendent.

Thanks
KIshori



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us