package com.javaproficiency;
public class Emp implements Cloneable {
//Object Cloning in java example?
int id;
String name;
public Emp(int id, String name) {
super();
this.id = id;
this.name = name;
}
public Emp clone() throws CloneNotSupportedException{
return (Emp ) super.clone();
}
public static void main(String[] args) {
Emp emp = new Emp(10, "java");
Emp emp1 = null;
try {
emp1 = emp.clone();
} catch (CloneNotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(" clone object is ");
System.out.println("id ="+ emp1.id+ " name ="+ emp1.name);
}
}
Output:
clone object is
id =10 name =java
public class Emp implements Cloneable {
//Object Cloning in java example?
int id;
String name;
public Emp(int id, String name) {
super();
this.id = id;
this.name = name;
}
public Emp clone() throws CloneNotSupportedException{
return (Emp ) super.clone();
}
public static void main(String[] args) {
Emp emp = new Emp(10, "java");
Emp emp1 = null;
try {
emp1 = emp.clone();
} catch (CloneNotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(" clone object is ");
System.out.println("id ="+ emp1.id+ " name ="+ emp1.name);
}
}
Output:
clone object is
id =10 name =java
thanks for sharing this useful info
ReplyDeleteBest Selenium Training in Chennai | Android Training in Chennai | Java Training in chennai | Webdesigning Training in Chennai
Thanks for sharing this wonderful article..keep updating..
ReplyDeleteITIL Certification Exam Center in Chennai | ITIL Certification Training in Chennai
Thanks for Blog sharing this interesting..
ReplyDeleteITIL Certification Exam Center in Chennai | ITIL Certification Training in Chennai