-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectCloneTest.java
More file actions
47 lines (38 loc) · 990 Bytes
/
ObjectCloneTest.java
File metadata and controls
47 lines (38 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.cloneable;
public class ObjectCloneTest implements Cloneable {
private int id;
private String name;
public ObjectCloneTest(int id, String name) {
super();
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
protected Object clone() throws CloneNotSupportedException {
// TODO Auto-generated method stub
return super.clone();
}
public static void main(String[] args) {
ObjectCloneTest cloneTest = new ObjectCloneTest(1, "Devendra");
System.out.println("Before cloaning : "+cloneTest.id+" : "+cloneTest.name);
//cloning objects
try {
ObjectCloneTest cloneTest2 = (ObjectCloneTest)cloneTest.clone();
System.out.println("After cloaning : "+cloneTest2.id+" : "+cloneTest2.name);
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
}
}