-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestCloning.java
25 lines (20 loc) · 1.14 KB
/
TestCloning.java
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
public class TestCloning {
public static void main(String[] args) {
// Create original shapes
Circle originalCircle = new Circle("Red", 5.0);
Rectangle originalRectangle = new Rectangle("Blue");
// Clone the shapes
Circle clonedCircle = (Circle) originalCircle.makeCopy();
Rectangle clonedRectangle = (Rectangle) originalRectangle.makeCopy();
// Output the original and cloned shapes
System.out.println("Original: " + originalCircle);
System.out.println("Cloned: " + clonedCircle);
System.out.println("Original: " + originalRectangle);
System.out.println("Cloned: " + clonedRectangle);
// Print hash codes to demonstrate they are different objects
System.out.println("Original Circle HashCode: " + System.identityHashCode(originalCircle));
System.out.println("Cloned Circle HashCode: " + System.identityHashCode(clonedCircle));
System.out.println("Original Rectangle HashCode: " + System.identityHashCode(originalRectangle));
System.out.println("Cloned Rectangle HashCode: " + System.identityHashCode(clonedRectangle));
}
}