??????????????main()?????У?new???Oject??????????????????clone?????????????????????????????"The method clone() from the type Object is not visible"
????why? ?????????????????ObjectTest???ж????Oject?????????????clone()?????????Object????clone()????????壬??????????????protected?????????????????????protected???ε????????????????????????????????????????????????Object????ObjectTest??????????У?????ObjectTest?????Object????Object??????????????????????????????Object???ò??????protected??????????????"??????е???????????"?????????
????"??????е???????????"??????????????????????е??????????????????????????????????????????????????????????protected???ε?????????/???????? ????????????????????????????????????protected???ε?????????super????????
?????????????????????????????????????????????

 

1 package com.corn.objectsummary;
2
3
4 public class ObjectTest {
5
6     public static void main(String[] args) {
7         ObjectTest ot1 = new ObjectTest();
8
9         try {
10             ObjectTest ot2 = (ObjectTest) ot1.clone();
11         } catch (CloneNotSupportedException e) {
12             // TODO Auto-generated catch block
13             e.printStackTrace();
14         }
15     }
16
17 }

?????????????????????????????????????
?????????????????й????л????"java.lang.CloneNotSupportedException"??????clone()??????δ??????????????????????Java?е????漲??
????clone()?????????????????Cloneable?????????????Cloneable??????????????????Object???clone()????????????CloneNotSupportedException????
????Cloneable????????????????????????????κη???????????Object.clone()??????????????????????á?
??????????????????????????????????????clone()?????????????

 

1 package com.corn.objectsummary;
2
3 public class ObjectTest implements Cloneable {
4
5     public static void main(String[] args) {
6
7         ObjectTest ot1 = new ObjectTest();
8
9         try {
10             ObjectTest ot2 = (ObjectTest) ot1.clone();
11             System.out.println("ot2:" + ot2);
12         } catch (CloneNotSupportedException e) {
13             // TODO Auto-generated catch block
14             e.printStackTrace();
15         }
16     }
17
18 }