-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCopyTest.java
64 lines (38 loc) · 873 Bytes
/
CopyTest.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class Shape{
String type;
int sides;
Shape(String type, int sides){
this.type = type;
this.sides = sides;
}
Shape(Shape s){
type = s.type;
sides = s.sides;
}
boolean equals(Shape s){
if(type == s.type & sides == s.sides){
return true;
}
else
return false;
}
void display(){
System.out.println(type + " has "+sides+" sides");
}
}
class CopyTest{
public static void main(String[] args) {
Shape s1 = new Shape("Square",4);
Shape s2 = s1;
Shape s3 = new Shape("Square",4);
Shape s4 = new Shape(s3);
s2.type = "Rect";
s1.display();
s2.display();
s3.display();
s4.display();
System.out.println("s1 == s2 "+s1.equals(s2));
System.out.println("s1 == s3 "+s1.equals(s3));
System.out.println("s1 == s4 "+s1.equals(s4));
}
}