• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

can static method be override ?

 
greenhorn
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can static method be override ?
if not then plz specify why ?
thanks in advance .
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you search the forum I'm pretty sure this question has been answered several times, and heavily discussed.

The short answer is no they aren't overridden, I think the correct term is hidden, but you can have a static method with the same signature in a subclass. The decision of which method to call is made at compile type based on the type of the reference not the type of the object during runtime.
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No static method can't be overridden & not hidden .
because you call static method from the class name so there is no point of hiding . the method will be called based on class name .

I hope it is right & clear ...
 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rathi ji:
No static method can't be overridden & not hidden .
because you call static method from the class name so there is no point of hiding . the method will be called based on class name .

I hope it is right & clear ...



Rathi,

I agree with Steven, Static methods cannot be overridden but they can be hidden.

Check this

Hope that helps you...

[ Fixed the link...]
[ January 25, 2005: Message edited by: Jay Pawar ]
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Link
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
static methods cannot be overridden, but they can be hidden by following the same rules on matching signatures, return type, exceptions, and accessability that apply to overriding.
[ January 25, 2005: Message edited by: Mike Gershman ]
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
static methods cant be overridden .you can use the static method with the same signature in the subclass but without the polymorphic feature.
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Although it is perfectly legal (in that the code will compile and run without throwing an exception) to redefine a static method in a subclass, you should never do so. Because static methods cannot be overridden, but rather are hidden, the reference to the static method is bound at compile time.

The problem is that executing a static method call on base and subclass references, while refering to the same object, yield different results.

This is a definite no-no .
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The output of this program will be :

I'm a Derived object
I'm a Base object

right ?

why you all are saying that static method can be hidden . Hidden means , not visible . but they are difinately visible . ( we can call super class static method with super classs name ... )

is there anything wrong ?
thanks .
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic