Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overriding methods

 
Terry McKee
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 101
Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Udayan Naik
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic