Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is cloneable interface?

Answer Posted / radhika

Java uses clone() of Object class to copy content of 1
object to other object. Classes can implement Cloneable
Interface to override clone() method of object class.

The following sample code will show the procedure for
implementing cloneable interface.
public class CloneExp implements Cloneable {

private String name;
private String address;
private int age;
private Department depart;
public CloneExp(){

}
public CloneExp(String aName, int aAge, Department aDepart) {

this.name = aName;
this.age = aAge;
this.depart = aDepart;
}

protected Object clone() throws CloneNotSupportedException {

CloneExp clone=(CloneExp)super.clone();

// make the shallow copy of the object of type Department
clone.depart=(Department)depart.clone();
return clone;

}
public static void main(String[] args) {

CloneExp ce=new CloneExp();

try {
// make deep copy of the object of type CloneExp
CloneExp cloned=(CloneExp)ce.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}

}
}

Is This Answer Correct ?    3 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is Java a dying language?

1036


What is final method?

1014


How to perform bubble sort in java?

949


Why to use nested classes in java?

1040


Can java arraylist hold different types?

990


How do you find the absolute value?

1001


What is a data structure java?

952


What does the “static” keyword mean? Can you override private or static method in java?

1038


How do you convert boolean to boolean?

1070


Define an applet in java?

1083


What is an infinite loop? How infinite loop is declared?

1017


What is java volatile?

960


Which keyword specify that a variable is effectively final ?

933


What is the syntax and characteristics of a lambda expression?

980


Explain the difference between abstract classes and interfaces in java?

1095