• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Another method invocation question...

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I understand that by extending Parent, Child inherits "method2()". When the method is called in main("p.method2()"), I understand that at run-time it is determined by the JVM that the underlying object which p refers to (of type Child) has its "method2()" called. Standard polymorphic call.
Once the inherited "method2()" starts executing, and the call to "method1()" is made, what I don't understand is why "method1()" from the Parent class is used instead of "method1()" from the Child class. Can anybody shed some light on why the result of this code was the following:
Parent's method2()
Parent's method1()
I was expecting this:
Parent's method2
Child's method1
Thanks,
Cliff
[ January 09, 2004: Message edited by: Cliff DeRose ]
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cliff,
Private methods are not inherited and are not overridden. The method1 in the child class does not override the method1 in the parent class.
 
Cliff DeRose
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So method1() in the Parent class and method1() in the Child class are two totally distinct things as viewed by the compiler? Is that correct? method1() in the Child class would be like making a new method specific only to the Child class - it has no relation at all to the Parent class?
Cliff
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's right there is no relation at all between the two methods because a private method cannot be overridden...
Kristof
reply
    Bookmark Topic Watch Topic
  • New Topic