• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about subclass methods with the same name of the superclass methods  RSS feed

 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a question. A method in subclass with the same name of a method in superclass should either override the super class's method or overload the superclass method right? It must be only among the two right? Any method which does not conform to the above rule gives compilation error right?

Thanks.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tested it out with your compiler? What results did you get?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Other possibilities are if the method is private or static in the superclass.

If it's private in the superclass, then it won't be inherited, so a method with the same name in the subclass is neither overridding nor overloading. If it's static in the superclass, then it cannot be overridden, but it can be hidden (or overloaded, depending on how you look at it).
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!