I was trying to override clone method in my class "Employee", when super.clone() was called, it gave exception but same code worked when I implemented "clonable". What my question is, every class has base class "Object". But when we call super.clone() it fails and on implementing clonable it works. why is it so?
Like shouldn't base class method can be accessible using "super" from subclass? why does it throws runtime exception?
public class Employee {
//explicit Employee extends Object didn't worked.
String name;
Integer id;
public Employee(String name, Integer id) {
this.name = name;
this.id = id;
}
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
}