Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt with Overriding concept in Java

 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May be a foolish question but still.

The Overriding method with lesser exceptions than specfied in the base class)

so why is it compulsary for us to deal with CloneNotSupportedException


 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You only need to deal with it in the first method that overrides clone():
You see, class A needs to catch it because Object.clone() specifies that it can throw a CloneNotSupportedException. Because A implements Cloneable, this exception will in fact never be thrown and can therefore be caught and ignored (although throwing an Error is better to indicate that something is still wrong if it occurs).

Class B no longer has to deal with it because A.clone() no longer throws it.
 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob for your excellent explanation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic