posted 8 years ago
Question 1:
Do we need to override the clone method if we implement the Cloneable interface, if there is no specific functionality defined.
If we have to override , what is the benefit of such override.
Question 2:
The below code is from other site (Source:http://javaconceptoftheday.com/difference-between-shallow-copy-vs-deep-copy-in-java/) ,
In the deep copy example
In the deep copy example the clone method definition is modified , even if we don’t override it and have another course object, add it to the student object and use the set method for changing the field , its going to behave the same.
What is the benefit of such override?
Example similar to the above:
Course course=new Course(“subj1″,”subj2”,"subj3");
Student std=new Student(123,“student1”,course);
Student std2=(Student ) std.clone();
Course course2=new Course(“subj1″,”subj2”,"subj3");
std2.setCourse(course2);
is this definition and the overrided clone method definition are the same?