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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:39:33+00:00 2026-06-16T16:39:33+00:00

Why can we access the clone() method using super. notation but cant access it

  • 0

Why can we access the clone() method using super. notation but cant access it by creating new object of type Object. For example if I do something like

Object obj = new Object();

then (using Eclipse) I cannot view the clone() method using the dot operator, which shows that obj is not able to view protected members of Object class (only public methods are visible).

Now if I were to use the super keyword i.e use super. I am able to view protected methods as well.

So my question is that in a class which does not explicitly inherit (extend) other class — i know that it gives an implicit call to the Object class constructor, i.e. the Object class is its superclass– why can super keyword access the protected members of Object class, but same is not achieved by creating instance of Object class (only the public members are visible to the instance of Object class)?

Here is clearer code (although it makes no sense but the first part complies and other doesn’t):

public class temp {

    public temp() {
        // TODO Auto-generated constructor stub
        TestBikes t1 = new  TestBikes();
        Object ob1 = new Object();
        try {
            t1 = (TestBikes)super.clone(); //SUPER KEYWORD IS ABLE TO ACCESS
                                                   //PROTECTED MEMBERS OF Object 
                                                   //CLASS   
        } catch (CloneNotSupportedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        try {
            t1 = (TestBikes)ob1.clone();  // HERE IS THE ERROR SAYING clone()
                                                  // FROM Object CLASS IS NOT VISIBLE
        } catch (CloneNotSupportedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
  • 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-16T16:39:34+00:00Added an answer on June 16, 2026 at 4:39 pm

    protected means only accessible by a sub-class (or a class in the same package) So you can access it in a sub-class using this or super or nothing, but not another instance.

    Your example compiles but it won’t run.

        try {
            t1 = (TestBikes)super.clone(); // creates a clone of temp, not a TestBikes
            t1 = (TestBikes)this.clone(); // does the same thing  
            t1 = (TestBikes)clone(); // does the same thing  
    
        } catch (CloneNotSupportedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    

    BTW: I know this is just an example but cloning an object in it’s constructor is a bad idea.


    It has to be protected so you can access it in subclasses which implement Cloneable. However, not all objects are cloneable so it is not generally accessible.

    Using super can access protected methods. Using a reference to make a method requires the method be accessible e.g. public or package local and in the same package.

    AFAIK, It is generally accepted that the clone()/Cloneable API is broken and should be avoided (except for primitive arrays) e.g. The Cloneable interface doesn’t have a Object clone(); method to make it public and it returns Object which have to cast.

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

Sidebar

Related Questions

Why I can access Session object in Page_Load method in instance of System.Web.UI.Page, but
We can access the valueStack (and other objects of ActionContext ) using OGNL but
I want to access JFrame(GraphicsConfiguration) using SwingBuilder.frame(), but I can't set it via the
I can access Spring beans in my Servlets using WebApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); in
I can access and show self.view and see the frame in the log but
How can hibernate can access a private field/method of a java class , for
As you know anyone can access strings in an native application using a hex
I'm currently creating a lot of classes that will access database using a connection
I can access the tags associated with a particular photo via the Graph API,
Can anyone let me know how can access an element of a list that

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.