File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Doubt with Overriding concept in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Doubt with Overriding concept in Java " Watch "Doubt with Overriding concept in Java " New topic
Author

Doubt with Overriding concept in Java

PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212
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

Joined: Oct 27, 2005
Posts: 19696
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212
Thanks Rob for your excellent explanation.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Doubt with Overriding concept in Java