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 821629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:40:18+00:00 2026-05-15T02:40:18+00:00

The Java documentation says: A class implements the Cloneable interface to indicate to the

  • 0

The Java documentation says:

A class implements the Cloneable
interface to indicate to the
Object.clone() method that it is
legal for that method to make a
field-for-field copy of instances of
that class.

Invoking Object’s clone method on an
instance that does not implement the
Cloneable interface results in the
exception CloneNotSupportedException
being thrown.

By convention, classes that implement
this interface should override
Object.clone (which is protected) with
a public method. See Object.clone()
for details on overriding this method.

Note that this interface does not
contain the clone method. Therefore,
it is not possible to clone an object
merely by virtue of the fact that it
implements this interface. Even if the
clone method is invoked reflectively,
there is no guarantee that it will
succeed.

And I have this UserProfile class:

public class UserProfile implements Cloneable {
    private String name;
    private int ssn;
    private String address;

    public UserProfile(String name, int ssn, String address) {
        this.name = name;
        this.ssn = ssn;
        this.address = address;
    }

    public UserProfile(UserProfile user) {
        this.name = user.getName();
        this.ssn = user.getSSN();
        this.address = user.getAddress();
    }

    // get methods here...

    @Override
    public UserProfile clone() {
        return new UserProfile(this);
    }
}

And for testing porpuses, I do this in main():

UserProfile up1 = new UserProfile("User", 123, "Street");
UserProfile up2 = up1.clone();

So far, no problems compiling/running. Now, per my understanding of the documentation, removing implements Cloneable from the UserProfile class should throw an exception in up1.clone() call, but it doesn’t.

I’ve read around here that the Cloneable interface is broken but I don’t really know what that means. Am I missing something?

  • 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-15T02:40:19+00:00Added an answer on May 15, 2026 at 2:40 am

    Now, per my understanding of the documentation, removing implements Cloneable from the UserProfile class should throw and exception in up1.clone() call, but it doesn’t.

    As long as your class still has an implementation of the clone() method, an exception will ofcourse not be thrown when you call it – it works just like any other method, there’s no special magic involved.

    The implementation of clone() in class Object is what throws the exception, but you’ve overridden that method.

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

Sidebar

Ask A Question

Stats

  • Questions 447k
  • Answers 447k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you mean in the same class then you are… May 15, 2026 at 7:31 pm
  • Editorial Team
    Editorial Team added an answer Maybe something like this: var publish = { method: 'stream.publish',… May 15, 2026 at 7:31 pm
  • Editorial Team
    Editorial Team added an answer Encapsulation and state management are very useful for situations like… May 15, 2026 at 7:31 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.