Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6974727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:16:32+00:00 2026-05-27T17:16:32+00:00

As part of our homework we are asked to implement an abstract class with

  • 0

As part of our homework we are asked to implement an abstract class with a clone method. The frame for the function is given:

/**
 * @effects Creates and returns a copy of this.
 */
public Object clone() {
    // TODO: Implement this method


}

The Shape class has two fields:

private Point location;
private Color color;

At the instructions we’re told that the method doesn’t throw a CloneNotSupportedException exception, and are also asked why it is so. At all the examples we’ve seen on the internet the clone method does throw a CloneNotSupportedException.

Would you please point us to the reason why this clone method shouldn’t throw that exception.

The method we have written is:

/**
 * @effects Creates and returns a copy of this.
 */

public Object clone() {
    Shape new_shape = (Shape)super.clone();
    new_shape.setColor(this.getColor());
    new_shape.location = (Point)location.clone();
    return new_shape;


}

It gives us an error on the (Shape)super.clone() part, saying:

Unhandled exception type CloneNotSupportedException, how should we create the clone method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:16:32+00:00Added an answer on May 27, 2026 at 5:16 pm

    Unhandled exception type CloneNotSupportedException

    That’s because the clone() method in the Object is defined to throw CloneNotSupportedException:

    protected Object clone() throws CloneNotSupportedException
    

    See API doc: Object#clone()

    To overcome that, you either need to handle it by using a try/catch block or redefine it by adding a throws clause.

    Update:

    At the instructions we’re told that the method doesn’t throw a CloneNotSupportedException exception, and are also asked why it is so.

    IMO –

    1. You are overriding a method in a super class. Only the return type, method name, and the parameter types are considered as method signature. So, while overriding a method you can omit the throws clause in the subclass even though the method in the superclass has it.
    2. Whenever your class implements the Cloneable interface, it’s telling the Object class that it is okay to make a clone of it. In such a case, a proper implementation of the clone method should call the super.clone method. Now, you can see that it’s actually the clone method in the Object class that actually makes the copy. So, we should leave up to the Object.clone() to throw that CloneNotSupportedException. And it will do so if any class in hierarchy does not implement the Cloneable interface.

    I hope that makes sense.

    Even though it’s kind of vast, in case you want to read about it more. It’s explained in Effective Java.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Part of our web app has a little Ajax method that will load a
Part of our website is protected with .htaccess style password protection. When you try
As part of our migration from .net 1.1 to .net 3.5, we had to
As part of our database revision control (and auto-installation) procedures we need to be
As part of our build process and evolving database, I'm trying to create a
As part of our automated build procedure we are trashing and reconstructing our IIS
As part of our web application's build process, I have set up our XSLT
As a part of our application I need to write simple workflow system which
We have a part of our program which can save a diagnostic file for
I am refactoring a part of our legacy app which handles exporting and importing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.