Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method hiding a method in super class

 
san ch
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi


a. Which method overrides a method in the superclass?
b. Which method hides a method in the superclass?
c. What do the other methods do?

i could identyfy that the second method will be override the method in the super class

i couldnt understand why method four hides the method four in the super class......

i am thinking, since static methods cant be overridden. any method which is implementd with the same signature in the sub class hides the super class method.

is my thinking right

pls explain

thank you
san
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are pretty much right. The confusion will come in if you try to call one of the static methods from an instance (which is why you should always call from a Class). If you:

the method in ClassA will be called, but make one little change:

and the method in ClassB will be called. This is because the method is chosen at compile time based on the type of the reference not the type of the object. You will also get similar behaviour with non-static methods that are overloaded take a different type of parameter such as:


I hope I helped more than confused.
 
san ch
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi steven

Thank you for the explaination it was indeed nice ......one small doubt
are there any other occasions where the super class method will be hidden by the subclass methods ....or is it only when the method is a static method
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method is only hidden when it's static.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic