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
Can a class have multiple subclasses?
When wait(), notify(), notifyall() methods are called does it releases the lock or holds the acquired lock?
What is int lol?
Explain the use of sublass in a java program?
Is object a data type?
Explain importance of throws keyword in java?
What is sortedmap interface?
How do I convert a numeric ip address like 192.18.97.39 into a hostname like java.sun.com?
Why do we need singleton class?
a thread is runnable, how does that work? : Java thread
Explain try and catch keywords in java?
Explain about main() method in java ?
What is a byte array?
Explain about interthread communication and how it takes place in java?
What does 3 dots mean in java?