-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoxClassExample.java
More file actions
36 lines (30 loc) · 990 Bytes
/
Copy pathBoxClassExample.java
File metadata and controls
36 lines (30 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
public class BoxClassExample {
double width, height, depth;
BoxClassExample(double width, double height, double depth) {
this.width = width;
this.height = height;
this.depth = depth;
}
// Constructor used if no arguments specified.
BoxClassExample() {
this.width = -1;
this.height = -1;
this.depth = -1;
}
// Constructor used for a cube.
BoxClassExample(double len) {
this.width = this.height = this.depth = len;
}
double getVol () {
return width * height * depth;
}
}
class BoxDemo {
public static void main(String args[]) {
BoxClassExample mybox1 = new BoxClassExample(10, 15, 20);
BoxClassExample mybox2 = new BoxClassExample();
BoxClassExample mybox3 = new BoxClassExample(10);
System.out.println("Volume of the box 1 is " + mybox1.getVol() + ".");
System.out.println("Volume of the box 3 is " + mybox3.getVol() + ".");
}
}