aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Static Override Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Static Override" Watch "Static Override" New topic
Author

Static Override

Shashank Hansraj Singh
Greenhorn

Joined: Jul 02, 2010
Posts: 3
Why can't we override static methods???


Life is beautiful
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
Because they are class methods and hence access to them is always resolved during compile time only using the compile time type information.Due to which even if you override them you will not be able take advantage of runtime polymorphism and the static method from the class of thr reference variable will be called.


SCJP 1.6 96%
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

You can't override it, what you can do is hides the static methods.

Nega Daga, After a long time!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
Just to add

Runtime polymorphism applies only to Instance methods.
Everything else could only be redefined and not overriden.

So static methods can be redefined in your subclass , but cannot overriden.

Even if you redefine, as said by neha, whcih method to call is decided at compile time by the type of reference.


Suppose static method "static method" is defined in both the Animal and Dog subclass.

In above code, static method of Animal is decided at compile time and subsequently run at run-time too by JVM.


Try out : Static method in Instance method. Override Instance Method !!! See which methods are being called. !!!


SCJP 6.0 96%

(Connecting the Dots ....)
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
yup....was in India for my brother's wedding....now I am back home so back to ranch too.
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Neha Daga wrote:yup....was in India for my brother's wedding....now I am back home so back to ranch too.

Is that so? So, you are now in USA?
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
no....am in UK.
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Neha Daga wrote:no....am in UK.

Ok, Thanks for the reply....
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
you are most welcome
btw congratulations 91% is a good score
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Neha Daga wrote:you are most welcome
btw congratulations 91% is a good score


Thanks a lot, you've helped me! Thanks.....
Shashank Hansraj Singh
Greenhorn

Joined: Jul 02, 2010
Posts: 3
Thank you, that was very precise..

I am also preparing for SCJP, I have the material to read, but Im looking for some full fledged practice test..
(And I want them free, that's the issue...)

Could I get some references???
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Shashank Hansraj Singh wrote:Thank you, that was very precise..

I am also preparing for SCJP, I have the material to read, but Im looking for some full fledged practice test..
(And I want them free, that's the issue...)

Could I get some references???


Well, go through ScjpMockTests and ScjpFaq for more details, there are so many links to free mocks. Try them....
Shashank Hansraj Singh
Greenhorn

Joined: Jul 02, 2010
Posts: 3
thanks,

I did google quite a few, but they just turned out 15-20 question sets, just one of them complete....

Was looking for applications that give summaries after test and keep timers too....
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Shashank Hansraj Singh wrote:thanks,

I did google quite a few, but they just turned out 15-20 question sets, just one of them complete....

Was looking for applications that give summaries after test and keep timers too....


So practice with ExamLab, it's a wonderful tool..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static Override