This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 215

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: 18497
    
  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)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Method invocation
 
Similar Threads
confused with the output from a code (Arrays)
Can anyone see this...
Polymorphism! correct me if i am wrong.
Static initializer doesn't return value.
Method invocation without Object