• 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

JVM - Overriding

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

Can anyone please tell me how the JVM internally decides which method to call during run time for eg.in case of overriding during inheritance.

Also how the complier internally decides which overloaded method to call during complie time.

Thanks in advance.
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JVM stores the runtime information of the object , this makes it possible to use the overriden method. For e.g. Suppose you create an instance of sublcass and assign it to superclass refernence JVM will have runtime info that the object is an instance os subclass so will invoke the subclass method.

Also how the complier internally decides which overloaded method to call during complie time.



This is done based on the method signature.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pradeep Bhat:
This is done based on the method signature.



More specifically, the most specific method is used.

Both compile time and runtime behavier are defined in detail by the JLS: http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#20448
 
reply
    Bookmark Topic Watch Topic
  • New Topic