File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Polymorphism and exceptions" Watch "Polymorphism and exceptions" New topic

Polymorphism and exceptions

Joey Sanchez
Ranch Hand

Joined: Jun 23, 2011
Posts: 88

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: 153

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: 88

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

Joined: Oct 15, 2010
Posts: 295

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 java67 Javarevisited
I agree. Here's the link:
subject: Polymorphism and exceptions
It's not a secret anymore!