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 Polymorphism and exceptions 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 "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: 145

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

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.


http://javarevisited.blogspot.com - java classpath - Java67 - java hashmap - java logging tips java interview questions Java Enum Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Polymorphism and exceptions
 
Similar Threads
Exception vs. Class subclasses and overloading
Exception Handling
Handle and Declare rule - Ducking exceptions
overriding static methods
Overriding doubt