Cloneable is only a  interface. 
if you override clone(), then even if you don't implement Cloneable, your clone code will still be executed.
But if you don't override clone, the default clone provided by jdk will check (this instanceof Cloneable).
If it is Cloneable, the clone() will do shallow copy for you. If it does not, exception will be thrown.Overall, it's a bad hack adopted by JDK. Typical abuse of "instanceof". Ugly, isn't it?

解决方案 »

  1.   

    谢谢ajoo(jet pig) ,给分了
      

  2.   

    then what about this one
    public class Inter extends Object implements Cloneable{
        private int a=0;
        private int b=0;
        public int get(){
            return a;
        }
        public int getb(){
            return b;
        }
        public void set(int a){
            this.a=a;
        }
        public Object clone() throws CloneNotSupportedException {
            Inter b=(Inter)super.clone();
           //b.a=this.a;
            return (Object)b;
        }    public static void main(String[] args) throws CloneNotSupportedException {
            Inter c=new Inter();
            Inter d;
            c.set(9);
            d=(Inter)c.clone();
            System.out.println(d.a);
        }
    }
    the result is 9,so in this program clone also works.
    but this instance of cloneable is Object,so"super.clone()"should produce a Clone of Object,not Inter.isn't it?
    unfortunately,it acturely produce a Clone of Inter.
    give me the green light pls
      

  3.   

    super.clone is Object.clone(). It uses reflection or whatever to clone your object (not only Object, the whole object)your overriding actually does nothing but delegate to the super.clone. It's equivalent to not overriding it.