public class Cuboid {
int length;
int breadth;
int height;
public int getVolume() {
return (length * breadth * height);
}
Cuboid() {
length = 1;
breadth = 1;
height = 1;
}
Cuboid(int l) {
length =l;
breadth = l;
height = l;
}
Cuboid(int l, int h) {
length = l;
breadth = l;
height = h;
}
Cuboid(int l, int b, int h) {
length = l;
breadth = b;
height = h;
}
}
Correct output:
The volume of cube1 is: 1 (l,w and H are all 1)
The volume of cube2 is: 125(length, breadth and height are all equal to 5)
The volume of cube3 is: 12(length and breadth is 2, and height is 3)
The volume of cube4 is: 6
public class Cuboid {
int length;int breadth;int height;
public int getVolume() {
return (length * breadth * height);
}
Cuboid() {
length = 1;
breadth = 1;
height = 1;
}
Cuboid(int l){
length =l;
length = breadth;
}
Cuboid(int l, int b) {
length = l;
breadth = b;
}
Cuboid(int l, int b, int h) {
length = l;
breadth = b;
height = h;
}
}
public class CubeTest {
public static void main(String[] args) {
Cuboid cube1 = new Cuboid();
System.out.println("The volume of cube1 is: "+ cube1.getVolume());
Cuboid cube2 = new Cuboid(5);
System.out.println("The volume of cube2 is: "+ cube2.getVolume());
Cuboid cube3 = new Cuboid(2,3);
System.out.println("The volume of cube3 is: "+ cube3.getVolume());
Cuboid cube4 = new Cuboid(3,2,1);
System.out.println("The volume of cube4 is: "+ cube4.getVolume());
}
}