This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 19655
    
  18

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt with Overriding concept in Java
 
Similar Threads
obj instanceof (String [] )
toString()
damn overriding again
Overriding Instance Variables (help)
Trying to access a servlet on button click