• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static methods

 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it legal to override a static method?
-Dale

------------------
By failing to prepare, you are preparing to fail.
Benjamin Franklin (1706 - 1790)
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even though you can have the same static method in the subclass as the super class, it's not actually overidding. i.e. you can not call super.superclassmethod() from the subclass.

Bosun
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dale
Static methods aren't overridden they're hidden. If you have a static method with the same signature in a subclass as there is in the super class the subclass method will hide the superclass method. In other words static methods behave like variables and are subject to early binding not runtime.
Check out this code:

The output is:
super class method
sub class method
super class method
You can see that the last method call, if the method were overridden, would have called the subclass method.
hope that helps


------------------
Dave
Sun Certified Programmer for the Java� 2 Platform
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic