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 the default execution method in java?
Explain java coding standards for interfaces?
What do you understand by an io stream?
What do you mean by mnemonics?
what is the significance of listiterator in java?
What is bubble sort in java?
What is substring in java?
What are class types in java?
What is generic type?
What is a class variable?
What is the difference between a method and a procedure?
What will happen if non-synchronized method calls a static synchronized method and what kind of lock it acquires?
What is the byte order of byte buffer?
Can an integer be null java?
Is java code slower than native code?