-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOverloadCons2.java
61 lines (48 loc) · 1.16 KB
/
OverloadCons2.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
/**
* C07 L04
*
* Box allows one object to initialize another.
*/
class Box2 {
double width;
double height;
double depth;
Box2(Box2 ob) {
width = ob.width;
height = ob.height;
depth = ob.depth;
}
Box2(double w, double h, double d) {
width = w;
height = h;
depth = d;
}
Box2() {
width = -1;
height = -1;
depth = -1;
}
Box2(double len) {
width = height = depth = len;
}
double volume() {
return width * height * depth;
}
}
public class OverloadCons2 {
public static void main(String[] args) {
Box2 mybox1 = new Box2(10, 20, 15);
Box2 mybox2 = new Box2();
Box2 mycube = new Box2(7);
Box2 myclone = new Box2(mybox1);
double vol;
vol = mybox1.volume();
System.out.println("Volume of mybox1 is " + vol);
vol = mybox2.volume();
System.out.println("Volume of mybox2 is " + vol);
vol = mycube.volume();
System.out.println("Volume of mycube is " + vol);
vol = myclone.volume();
System.out.println("Volume of myclone is " + vol);
}
}