This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes method hiding a method in super class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "method hiding a method in super class" Watch "method hiding a method in super class" New topic
Author

method hiding a method in super class

san ch
Ranch Hand

Joined: Oct 18, 2004
Posts: 68
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

Joined: Dec 29, 2004
Posts: 1071
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

Joined: Oct 18, 2004
Posts: 68
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

Joined: Dec 29, 2004
Posts: 1071
The method is only hidden when it's static.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: method hiding a method in super class