-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstructors.java
44 lines (40 loc) · 970 Bytes
/
constructors.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
package src.constructor;
class box2 {
double width, height, depth;
box2() {
System.out.println("Initializing Box...");
width = 10;
height = 21;
depth = 31;
}
double volume() {
return width * height * depth;
}
}
class boxDemo2 {
public static void main(String[] args) {
box2 b21 = new box2();
box2 b22 = new box2();
System.out.println("Volume of b21 is " + b21.volume());
System.out.println("Volume of b22 is " + b22.volume());
}
}
class box3 {
double width, height, depth;
box3(double w, double h, double d) {
width = w;
height = h;
depth = d;
}
void volume() {
System.out.println("Volume is " + width*height*depth);
}
}
class boxDemo3 {
public static void main(String[] args) {
box3 b31 = new box3(4, 7, 11);
box3 b32 = new box3(21, 54, 11);
b31.volume();
b32.volume();
}
}