This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

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’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Polymorphism and exceptions
It's not a secret anymore!