write a java program to create a super class called Box which is dealing
with following data members and member functions:
Data Members:
double [width, height, depth]
Box(): default constructor
Box(......): parameterised constructor
Member functions
double getVolume(): to calculate the volume of a box
Create a sub class called MatchBox to deal with the following data members
& member functions:
data members: double weight
to declare a default constructor
to invoke the parent class parameterised constructor
class Box{
double width;
double height;
double depth;
Box(){
}
Box(double w, double h, double d){
width = w;
height = h;
depth = d;
}
void getVolume(){
System.out.println("Volume is : "+width*height*depth);
}
}
public class MatchBox extends Box{
double weight;
MatchBox() {
}
MatchBox(double w, double h, double d, double m) {
super(w,h,d);
weight = m;
}
public static void main(String args[])
{
MatchBox mb1 = new MatchBox(10,10,10,10);
mb1.getVolume();
System.out.println("width of MatchBox 1 is " + mb1.width);
System.out.println("height of MatchBox 1 is " + mb1.height);
System.out.println("depth of MatchBox 1 is " + mb1.depth);
System.out.println("weight of MatchBox 1 is " + mb1.weight);
}
}