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
Is java a super set of javascript?
What is the size of int in 64-bit jvm?
Can I use % with real numbers?
What is application tier?
What is string in java with example?
What is Java Reflection API? Why it’s so important to have?
can used Protected Class outside Function.?
How do you test a method for an exception using junit?
What is use of set in java?
What is the final field modifier?
What are format specifiers in java?
What is 32 bit float?
How garbage collection is done in java?
Can you sort a list in java?
does java support pointers?