-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoxDemo5.java
More file actions
40 lines (34 loc) · 813 Bytes
/
BoxDemo5.java
File metadata and controls
40 lines (34 loc) · 813 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
37
38
39
40
// This Program includes a method inside the box class
class Box{
double width;
double height;
double depth;
// Display volume of a box
double volume(){
return width * height * depth;
}
//Setting the dimensions.
void setDim(double w, double h, double d){
width = w;
height = h;
depth = d;
}
}
class BoxDemo5{
public static void main(String args[]){
Box mybox1 = new Box();
Box mybox2 = new Box();
double vol;
//assign values to mybox1 variables.
mybox1.setDim(10,20,15);
/*assign different
value to box 2*/
mybox2.setDim(3,6,9);
// display vol of !st box.
vol = mybox1.volume();
System.out.println("Volume is " + vol);
//display vol of 2nd box
vol = mybox2.volume();
System.out.println("Volume is " + vol);
}
}