-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoxDemo4.java
More file actions
36 lines (32 loc) · 765 Bytes
/
BoxDemo4.java
File metadata and controls
36 lines (32 loc) · 765 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
// 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;
}
}
class BoxDemo4{
public static void main(String args[]){
Box mybox1 = new Box();
Box mybox2 = new Box();
double vol;
//assign values to mybox1 variables.
mybox1.width = 10;
mybox1.height = 20;
mybox1.depth = 15;
/*assign different
value to box 2*/
mybox2.width= 3;
mybox2.height = 6;
mybox2.depth = 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);
}
}