• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Shallow and Deep Copy in Java

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic