• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

method hiding a method in super class

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The method is only hidden when it's static.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic