Answer Posted / saravanan sagadevan
clonable interface is a marker interface to clone the
object.If we want to clone the object then we have to
override clone method .
public Object clone() throws CloneNotSupportedException(){
try{
super.clone();
}catch(CloneNotSupportedException exe){
}
There are two types of clone 1. Shallow copy 2.Deep copy
1. Shallow Copy:
Default copy is shallow copy . Ex :
Class Person {
private Car car ;
public Car getCar(){
this.car=car
}
public Object clone() throws CloneNotSupportedException
(){
try{
super.clone();
}catch(CloneNotSupportedException exe){
}
When Person object is copied, new perosn object will be
created , but Member object car is shared by both copies.
If you make changes in Car object that will be reflected in
cloned object also.
Deep Copy:
===========
For Deep copy , seprate Parent(Person) and child object
will be created .There two copies will be created
| Is This Answer Correct ? | 4 Yes | 2 No |
Post New Answer View All Answers
Why set is used in java?
What are different types of multitasking?
What is the purpose of the system class in java?
What is treeset in java?
What is the purpose of sizeof operator?
Who found java?
How do you use nextline in java?
What is assembly condition codes?
What is boolean law?
What are the advantages of functions?
What is java virtual machine? Explain
What classes of exceptions may be thrown by a throw statement?
What is parsing a string?
What is the difference between path and classpath variables?
Explain the difference between hashmap and hashtable in java?