File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Polymorphism and exceptions 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 "Polymorphism and exceptions" Watch "Polymorphism and exceptions" New topic
Author

Polymorphism and exceptions

Joey Sanchez
Ranch Hand

Joined: Jun 23, 2011
Posts: 86

Class A method m() throw an Exception that have to be handled even if the method called is from class B.

Is that because the method invocation is done at runtime based on object reference but the compilations take care of reference type?

Karn Kumar
Ranch Hand

Joined: Aug 06, 2009
Posts: 146

yes , the compiler will check for the polymorphic reference and method defined in it .So here class A reference is polymorphic reference hence compiler will check the method in A and hence we need to handle it ...
Joey Sanchez
Ranch Hand

Joined: Jun 23, 2011
Posts: 86

Thank you very much, it's a little tricky.
Javin Paul
Ranch Hand

Joined: Oct 15, 2010
Posts: 294

Rule of thumb , Compiler can only verify type information and not the Object related information. here Compiler thinks method m() from A and not B.


SQL Query Interview Question
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Polymorphism and exceptions