This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Method invocation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Method invocation" Watch "Method invocation" New topic
Author

Method invocation

Sudhanshu Mishra
Ranch Hand

Joined: May 28, 2011
Posts: 217

Hi all,
I am a bit confused about the way method invocation works.
Do we really need an object for the method invocation at all times or it is just at the time of method overriding that the JVM will look at the real object type.I am not convinced with this fact.What happens if their is no overriding at all?how does the method invocatin tkes place then.

I have recieved few answers but I am not convinced.I have always read that an object is required for method invocation and the JVM always looks at the real object type while method invocation.

Please clear my concept.

Thanks....
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18876
    
  40

Sudhanshu Mishra wrote:Hi all,
I am a bit confused about the way method invocation works.
Do we really need an object for the method invocation at all times or it is just at the time of method overriding that the JVM will look at the real object type.I am not convinced with this fact.What happens if their is no overriding at all?how does the method invocatin tkes place then.


Basically, to call a static method, then no. To call an instance method (ie. non-static method), then yes. And of course, the reason is because an instance method, has access to its this object, so you need to actually provide one.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Method invocation