-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBox.java
More file actions
25 lines (22 loc) · 666 Bytes
/
Copy pathBox.java
File metadata and controls
25 lines (22 loc) · 666 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
// Demonstrates the creation and use of a simple class.
public class Box {
double width;
double height;
double depth;
// Constructor to initialize the dimensions of the box
Box(double w, double h, double d) {
width = w;
height = h;
depth = d;
}
// Method to calculate the volume of the box
double volume() {
return width * height * depth;
}
public static void main(String[] args) {
// Create an instance of Box
Box myBox = new Box(10, 20, 15);
// Calculate and print the volume of the box
System.out.println("Volume of the box is: " + myBox.volume());
}
}