The method clone() from object is not visible?

后端 未结 8 680
半阙折子戏
半阙折子戏 2020-12-08 06:46

Question:

package GoodQuestions;
public class MyClass {  
    MyClass() throws CloneNotSupportedException {
        try {
            throw new CloneNotSuppo         


        
8条回答
  •  一生所求
    2020-12-08 07:05

    clone() has protected access. Add this in MyClass

    public Object clone(){  
        try{  
            return super.clone();  
        }catch(Exception e){ 
            return null; 
        }
    }
    

    Also Change to public class MyClass implements Cloneable

提交回复
热议问题