• Post Reply Bookmark Topic Watch Topic
  • New Topic

JVM - Overriding  RSS feed

 
Goldilocks Goldilocks
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • 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.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!