File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Help needed! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help needed!" Watch "Help needed!" New topic
Author

Help needed!

kotoisin
Greenhorn

Joined: Nov 08, 2004
Posts: 5
In Java, a method call on an object such as x.f() is resolved, when the program executes, not when it is compiled, in order to support polymorphism. Name two situations, where The Java Compiler can determine the exact method to be called before the program executes..?

Please help, so far I am thinking about, if it can have anything to do with casts?
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
If f() is a static method, which f() is called is determined by the compiler based on x's declared type.

As for a second case, if f() is declared final in the class that x is declared to be. Heh, that might take an example.I would expect that line 2 will be compiled as a polymorphic lookup of f() since it could be A.f() or B.f() based on the instance x references at runtime.

However, line 5 should be compiled to directly call B.f() since that's the only option for a C (or any subclass of it).

Of course, IANAJVMA, so YMMV.
kotoisin
Greenhorn

Joined: Nov 08, 2004
Posts: 5
Thank you. It helped me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help needed!
 
Similar Threads
bridge C++/Java?
How to call windows exe file placed in windows machine from unix machine
JAVA Virtual Machine
Program without a main method
log4j:WARN Please initialize the log4j system properly