Java Program to Create a class Box that uses a parameterized constructor to initialize the dimensions of a box.

Create a class Box that uses a parameterized constructor to initialize the dimensions of a box.

The dimensions of the Box are width, height, depth. 

The class should have a method that can return the volume of the box. 

Create an object of the Box class and test the functionalities.



Source code:

1:  public class Box {  
2:       private double width;  
3:       private double height;  
4:       private double depth;  
5:       Box(int width, int height, int depth){  
6:            this.width = width;  
7:            this.height = height;  
8:            this.depth = depth;  
9:       }  
10:       double getVolume() {  
11:            return width * height * depth;  
12:       }  
13:       public static void main(String[] args) {  
14:            // TODO Auto-generated method stub  
15:            Box box = new Box(10, 20, 30);  
16:            System.out.print("The volume of Box is " + box.getVolume());  
17:       }  
18:  }