• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need explanation - Kathy Sierra book's exam watch on Page no 105

 
Kaleem Anwar
Ranch Hand
Posts: 40
2
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Could anyone explain the following example, referring to Kathy Sierra book's exam watch on Page no 105? I need to understand why this code won't compile. Methods are called based on the type of the reference variable and then at run time JVM dynamically invoke the overridden version of the method based on the object type. As per the rules, the overridding method can reduce or eliminate the checked exception... So, what next ....??

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler looks at the variable declaration. Looking at it from that point of view, we have:



The compiler thinks. "I see there is an eat() method on Dog2 that doesn't throw an exception so all is cool." Then:



Now the compiler thinks, "I see there is an eat() method on Animal that throws an exception. Uh oh"
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kaleem Anwar wrote:Could anyone explain the following example, referring to Kathy Sierra book's exam watch on Page no 105? I need to understand why this code won't compile.

Have a look at this topic. It's about the same Exam Watch as your question and it has a post with an extensive and awesome explanation of what's going on (*). So have a look at that topic and read every post carefully. I'm pretty sure it will answer all your questions and clear your doubts. If you still have doubts/questions, just let us know by clicking on the "post reply" button

Hope it helps!
Kind regards,
Roel

(*) I made that post, so I might be a little biased
 
Kaleem Anwar
Ranch Hand
Posts: 40
2
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:
Kaleem Anwar wrote:Could anyone explain the following example, referring to Kathy Sierra book's exam watch on Page no 105? I need to understand why this code won't compile.

Have a look at this topic. It's about the same Exam Watch as your question and it has a post with an extensive and awesome explanation of what's going on (*). So have a look at that topic and read every post carefully. I'm pretty sure it will answer all your questions and clear your doubts. If you still have doubts/questions, just let us know by clicking on the "post reply" button

Hope it helps!
Kind regards,
Roel

(*) I made that post, so I might be a little biased


Perfect!!

Thanks alot Roel.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic