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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:47:20+00:00 2026-06-13T12:47:20+00:00

I am confused regarding overriding clone method in the class for which I want

  • 0

I am confused regarding overriding clone method in the class for which I want cloned object.

Object class has protected object method and as per the protected behavior which is When a method is protected, it can only be accessed by the class itself, subclasses of the class, or classes in the same package as the class.

As every class in Java extends from Object, so it should have clone method but still we are forced to override clone. Why is it required?

Also, I have read at some places to override the clone object and make it public. I wonder, why is it so?

All answers are welcome.

  • 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-06-13T12:47:21+00:00Added an answer on June 13, 2026 at 12:47 pm

    As every class in Java extends from Object, so it should have clone
    method but still we are forced to override clone

    No you are not forced to override the clone method. In inheritance, when you inherit a class, you are not forced to override it’s method. Its modifier being public or protected doesn’t make much of a difference. However, if you want to invoke a method directly on super class reference, then that method has to be public. Protected methods are accessible only through inheritance. That is you can only access them through subclass reference. Or if you override the method, you can access them through super keyword.

    Having said that, you should not override clone method, as it is broken. Because, for a class to be cloned, you need to implement the Cloneable interface. And then your class uses the clone method of Object class instead. Because, Cloneable interface doesn’t exactly have any method for cloning. It would be a better option to use Copy Constructor instead.

    public class A {
       private int data;
       public A() {
       }
    
       public A(A a) {
          this.data = a.data;
       }
    }
    

    For more details, I would suggest to go through this chapter of Joshua Bloch's Effective Java, which covers all aspects of using clone method.

    Effective Java- Item # 11 – Override clone judiciously

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

Sidebar

Related Questions

I need help regarding DDA algorithm , i'm confused by the tutorial which i
I am new to Semantic Web and confused regarding RDFs and Ontology. Can someone
I'm new to C++ and a bit confused regarding auto_ptr. I have a class
Im confused regarding which scope should i use. Here i have a module, that
I am a bit confused regarding C# WPF. How can I set a WPF
I am little bit confused regarding backend working of anonymous class, like if we
I'm a newbie of iOS development and I'm confused regarding universal app. We can
I'm a bit confused regarding the document architecture. Lets look at MSN for Mac
I'm confused regarding each() and .each()... I think I need to use both, but
I am a little confused with the documentation regarding the different types of sending

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.