• 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

Reference variable calls a method or instance of the class calls?

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Namaste Friends !!

please explain me why " HighDrop 1" is the output following code-:


What I think is obj of Low class does not have access to drop() method of High class and "High hl" reference variable is referring to obj of class Low so it should give compile error...

I am wrong...so please explain me......

Thanks

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi vishal ,Here in this code jvm will invoke method of your reference variable not of the subtype object's method ,it decides at compile time that it has to invoke reference variable's method and your method in subclass is also private, so it is redefining that method not overloading or overriding it.
 
vishal mishra
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

shiva mistry wrote:Hi vishal ,Here in this code jvm will invoke method of your reference variable not of the subtype object's method ,it decides at compile time that it has to invoke reference variable's method and your method in subclass is also private, so it is redefining that method not overloading or overriding it.


Namaste Shiva and

Thank you !!
 
Do not meddle in the affairs of dragons - for you are crunchy and good with ketchup. Crunchy tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic