• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static Override

 
Shashank Hansraj Singh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why can't we override static methods???
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't override it, what you can do is hides the static methods.

Nega Daga, After a long time!
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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. !!!
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup....was in India for my brother's wedding....now I am back home so back to ranch too.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no....am in UK.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neha Daga wrote:no....am in UK.

Ok, Thanks for the reply....
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are most welcome
btw congratulations 91% is a good score
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic