-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram11.java
More file actions
61 lines (41 loc) · 1.1 KB
/
Copy pathProgram11.java
File metadata and controls
61 lines (41 loc) · 1.1 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// WAP to Create a class box having height, width , depth as the instance variables &
//calculate its volume. Implement constructor overloading in it. Create a subclass
//named box_new that has weight as an instance variable. Use super in the box_new
//class to initialize members of the base class
package program11;
class Box {
private double height;
private double width;
private double depth;
public Box() {
this.height = 0;
this.width = 0;
this.depth = 0;
}
public Box(double value) {
this.height = value;
this.width = value;
this.depth = value;
}
public Box(double height, double width, double depth) {
this.height = height;
this.width = width;
this.depth = depth;
}
public double getVolume() {
return (height * width * depth);
}
}
class Box_new extends Box {
private double weight;
Box_new(double height, double width, double depth, double weight) {
super(height, width, depth);
this.weight = weight;
}
}
public class Program11 {
public static void main(String[] args) {
Box_new a = new Box_new(5,10,12,6);
System.out.println("The Volume is: "+a.getVolume());
}
}