What is cloneable interface?

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


Please Help Members By Posting Answers For Below Questions

What is the default execution method in java?

865


Explain java coding standards for interfaces?

848


What do you understand by an io stream?

793


What do you mean by mnemonics?

748


what is the significance of listiterator in java?

805


What is bubble sort in java?

843


What is substring in java?

813


What are class types in java?

795


What is generic type?

788


What is a class variable?

797


What is the difference between a method and a procedure?

753


What will happen if non-synchronized method calls a static synchronized method and what kind of lock it acquires?

741


What is the byte order of byte buffer?

778


Can an integer be null java?

754


Is java code slower than native code?

764