GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes overriding methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "overriding methods" Watch "overriding methods" New topic
Author

overriding methods

Terry McKee
Ranch Hand

Joined: Sep 29, 2000
Posts: 173
According to the RHE static methods may not be overridden. However, I devised a simple program that seems to override. Could someone shed some light on this issue? Thanks in advance.
Anil Kollur
Ranch Hand

Joined: Mar 25, 2000
Posts: 101

H! Terry,
yah, its true that static methods can not be overridden, but they may be shadowed in the subclass by defining the same method with same name, return type, arguments and static keyword ofcourse. The method in the superclass becomes shadowed by the method in the subclass.

------------------
Graaaasp the Concepts and Graaaab SCJP. :Anil Kollur:


Everyday is a Learning phase! Hence ask "What have I learnt today?"
Udayan Naik
Ranch Hand

Joined: Oct 18, 2000
Posts: 135
Hi Terry.RHE says that static methods cannot be overriden because they do not participate in runtime polymorphism.That is , if i have code that looks like

then the method in class A will be called and not the one in class B.Since static members belong to a class and not to a particular object,the static method will be called according to reference.
Thus the static method in child class will HIDE the method in base class,and not override it.
I hope I have been clear enough.
------------------
Come on in !! Drinks are on the house in the Big Moose Saloon !!
[This message has been edited by Udayan Naik (edited November 08, 2000).]


Udayan Naik<BR>Sun Certified Programmer for the Java 2 Platform
 
GeeCON Prague 2014
 
subject: overriding methods