Question:
package GoodQuestions;
public class MyClass {
MyClass() throws CloneNotSupportedException {
try {
throw new CloneNotSuppo
This error occurs because in Object class clone() method is protected. So you have to override clone() method in respective class. Eg. Add below code in MyClass
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
Also implement Cloneable interface.
Eg. public class MyClass implements Cloneable