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

How we can make copy of a java object?

658


what is server side caching?

1611


Explain access specifiers?

661


What is an inner class in java?

529


What is a generic data type?

574






What is java ceil?

574


Define a package.

572


Can we have try without catch block?

647


what is inner class in java?

628


What is formatted output?

514


What’s meant by anonymous class?

606


What is java util concurrentmodificationexception?

504


What are the two ways to create a thread?

538


What are the four pillars of java?

614


What are wrapped classes in java programming?

591