This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.



Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Polymorphism and exceptions  RSS feed

 
Joey Sanchez
Ranch Hand
Posts: 92
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 153
Eclipse IDE Java Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much, it's a little tricky.
 
Javin Paul
Ranch Hand
Posts: 295
Eclipse IDE Firefox Browser Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!