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
Explain the importance of finally over return statement?
What is the locale class in java programming?
What is qualitative variable?
What type of variable is error flag?
What is a map in java?
Can we declare main () method as non static?
What is difference between null and void?
What is callablestatement? How you can call stored procedure to pass in parameter?
Can Exception handling we can handle multiple catch blocks?
Explain the difference between map and flatmap stream operation?
What are the two types of streams offered by java 8?
What is difference between next () and nextline () in java?
Is 0 an even number?
What is the size of boolean variable?
What is a boolean in java?