aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why static methods can not be overridden Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why static methods can not be overridden" Watch "why static methods can not be overridden" New topic
Author

why static methods can not be overridden

teja dharma
Ranch Hand

Joined: Feb 07, 2009
Posts: 51
why static methods can not be overridden ?


SCJP 5
Himalay Majumdar
Ranch Hand

Joined: Sep 28, 2008
Posts: 324
Because the belong to class..not Object


SCJP 1.6, SCWCD 5.0, SCBCD 5.0 [loading..]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14430
    
  23

See this in the FAQ: http://faq.javaranch.com/view?OverridingVsHiding


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Guilherme Bazilio
Greenhorn

Joined: Mar 02, 2009
Posts: 23
Static methods cannot be overriden because they belong to the class, not to an instance of that class.
A static method don't need an instance to be accessed.

So, when you think you are overriding a static method, the only thing you are doing is redefining it.

(If I'm wrong just tell me please :P)
Ram Prasad
Greenhorn

Joined: Feb 02, 2008
Posts: 9
Bazilio is correct.
static methods cannot be overridden.

you can define the same static method in different classes and this mechanism is called redefining. The compiler accepts it and doesn't throw any error. But in run time you wont get the expected results of overriding since it is not actually a overriding.
i guess this should clarify your doubt tejahyd
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 823

Ram Prasad wrote:Bazilio is correct.
static methods cannot be overridden.

you can define the same static method in different classes and this mechanism is called redefining.


I think it is known as hiding


Regards, Sud.
SCJP 5 ScjpFAQ JLS
Guilherme Bazilio
Greenhorn

Joined: Mar 02, 2009
Posts: 23
sudipo shekhar wrote:
I think it is known as hiding


I think hiding is also a valid name. K&B book calls redefine.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why static methods can not be overridden