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

can we override the static methods ?

 
Krishna prasad ambala
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we override the static methods ?
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beforehand, what is your opinion? Can you just try the same in a sample program and update us with the result what you get?

It would be so nice and add more values to the knowledge!
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you can't.

I think this is one instance where we break the usual JavaRanch practice and give a straight answer.

No, you can't.

If you have two static methods with the same signature, they hide each other. See this FAQ, which is the same as I quoted on your other thread here. Although the compiler will happily accept hidden static methods, this can lead to a lot of confusion in use; you can have instance methods from one class and static methods from another expressed, so if you are tempted to hide anything: don't!
 
Thomas Kennedy
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My understanding of this is that because static methods belong to the class they are not involved in polymorphism, and because they are not involved in polymorphism they cannot be considered as overriding one another. For example:



It prints "foo" because the compiler inserted a call to foo.snap() into the bytecode. It doesn't matter that a zoop object was created at runtime. In effect, no override occurred.
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we override the static methods?
A quick search would have led you to these recent topics: Static Methods in an Interface, and then what linking mechanism uses java (early or late) which both discuss this in great detail.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic