-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainExp.java
More file actions
21 lines (20 loc) · 742 Bytes
/
Copy pathMainExp.java
File metadata and controls
21 lines (20 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package com.shallowcopy;
/**
* @author ManhKM on 2/14/2022
* @project Java-String
*/
public class MainExp {
public static void main(String[] args) throws Exception{
ObjExp o1 = new ObjExp("123", new ObjExp("child 123"));
ObjExp o2 = new ObjExp("abc", new ObjExp("child abc"));
System.out.println("Init: " + o1 + " | " + o2);
o2=(ObjExp)o1.clone();
System.out.println("After assign: " + o1 + " | " + o2);
o2.setContent("456");
o2.getChild().setContent("child 456");
System.out.println("After set o2: " + o1 + " | " + o2);
o1.setContent("789");
o1.getChild().setContent("child 789");
System.out.println("After set o1: " + o1 + " | " + o2);
}
}