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
What is space character in java?
Is java developer a good career?
Should you use singleton pattern?
Is main a function?
Explain the advantages of packages in java?
Which eclipse is best for java?
What do you mean by thread safe?
What is methodological theory?
What will happen if a thrown exception is not handled?
how to create multithreaded program? Explain different ways of using thread? When a thread is created and started, what is its initial state? : Java thread
What are the two environment variables that must be set in order to run any java programs?
Where pragma is used?
How can we create a thread in java?
how can you catch multiple exceptions in java?
What are keywords in java?