protected « Clone « Java Class Q&A

Home
Java Class Q&A
1.abstract class
2.Base class
3.class hierarchy
4.class name
5.class version
6.Class.forName
7.ClassCastException
8.Clone
9.constant
10.Constructor
11.Development
12.DTO
13.encapsulation
14.equal method
15.extend Class
16.getter
17.hashcode
18.Inheritance
19.inner class
20.interface
21.main class
22.Method
23.NoClassDefFoundError
24.NoSuchMethodError
25.NoSuchMethodException
26.object reference
27.overload
28.parent class
29.Polymorphism
30.private
31.Private Field
32.Recursive
33.setter
34.Static
35.Static Class
36.subclass
37.Super
38.toString
39.Wrapper Class
Java Class Q&A » Clone » protected 

1. What is the reason behind Object.clone() is protected    stackoverflow.com

Here is my test code for checking the clone method working,

class Test{
  int a;
  public void setA(int value){
a = value;
  }
  public int getA(){
   return ...

2. I am getting clone() has protected access in java.lang.Object    coderanch.com

Test1.java ------------- package paul1; public class Test1 { public String name; public Test2 objTest2; public Test1(){ objTest2 = new Test2(); } public void setName(String name){ this.name = name; } public String getName(){ return name; } public void setObjTest2(Test2 objTest2){ this.objTest2 = objTest2; } public Object getObjTest2(){ return objTest2; } } Test2.java --------- package paul1; public class Test2 implements Cloneable { public ...

4. Why Clone method is Protected    coderanch.com

here's something to note: if you take a look at the source for Cloneable (note the misspelling---it should really be Clonable) you see this: public interface Cloneable { } yes, it's empty. when you declare a class and put "implements Cloneable" after the class name, there's nothing to implement---well, 'cept the semantics of what the interface represents. This sort of interface ...

5. Why is clone() method protected?    coderanch.com

Almost, I think. Suppose it was public. That means that you can call clone() from any other class. Now - you don't want to do this, because you want to control the call for clone() on your objects. Also, you can always declare your class final - and that's where you end the inheritance. So - if you can't extend class ...

6. protected clone() doubt    coderanch.com

I think your question is more about protected access than about the clone method itself. As far as class Integer is concerned, Method clone is just an another example of a proteced method. So, we could as easily use the following example:package com.acme.widget; public class Rocket { protected void launch() {...} }Your question then is why can't you do the following:Rocket ...

8. Why couldn't call object's protected method:clone( )?    forums.oracle.com

I don't know what "No indicator" is supposed to mean, but the problem is that you can only call a protected method on class through a reference to the current class or one of its children. clone() is protected in Object but your executeObject is not of the same type as the class where you're trying to use it (PeriodicExe), nor ...

9. Why clone() method in Object class as a "protected" ?    forums.oracle.com

Who cares? To know that you'd have to ask the original designers what they were thinking. Anything else is just speculation. Just use it as is & be done with it. If you still want to pursue this pointless question, go buy a book on the history of Java. The answer has no effect on how you write you code.

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.