File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Java 8 in Action this week in the Java 8 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
 
Similar Threads
JQ+ question
Can someone please explain local variables inside a static method?
Dan exam doubt 17
what's the difference between "override" and "hide"?
Coding Standard - Time Cost Factor