[go: up one dir, main page]

0% found this document useful (0 votes)
13 views1 page

Matchbox

The document describes a Java program that defines a superclass called Box with data members for width, height, and depth, along with constructors and a method to calculate volume. It also defines a subclass MatchBox that adds a weight attribute, includes its own default constructor, and invokes the parent class's parameterized constructor. The main method creates an instance of MatchBox, calculates its volume, and prints its dimensions and weight.

Uploaded by

arkadippanja21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

Matchbox

The document describes a Java program that defines a superclass called Box with data members for width, height, and depth, along with constructors and a method to calculate volume. It also defines a subclass MatchBox that adds a weight attribute, includes its own default constructor, and invokes the parent class's parameterized constructor. The main method creates an instance of MatchBox, calculates its volume, and prints its dimensions and weight.

Uploaded by

arkadippanja21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

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);

}
}

You might also like