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
How we can make copy of a java object?
what is server side caching?
Explain access specifiers?
What is an inner class in java?
What is a generic data type?
What is java ceil?
Define a package.
Can we have try without catch block?
what is inner class in java?
What is formatted output?
What’s meant by anonymous class?
What is java util concurrentmodificationexception?
What are the two ways to create a thread?
What are the four pillars of java?
What are wrapped classes in java programming?