forked from iRupam/NewtonSchoolInfinityJune21
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuperKeywordExample.java
More file actions
74 lines (59 loc) · 1.56 KB
/
SuperKeywordExample.java
File metadata and controls
74 lines (59 loc) · 1.56 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package InfinityJune21.OOPS.Inheritance;
class Box {
private double width;
private double height;
private double length;
Box(Box ob) {
width = ob.width;
height = ob.height;
length = ob.length;
}
Box(double w, double h, double l) {
width = w;
height = h;
length = l;
}
Box() {
width = height = length = -1;
}
Box(double len) {
width = height = length = len;
}
double volume() {
double volume = length * width * height;
return volume;
}
}
class BoxWeight extends Box {
double weight;
BoxWeight(BoxWeight ob) {
super(ob);
weight = ob.weight;
}
BoxWeight(double w, double h, double l, double m) {
super(w, h, l);
weight = m;
}
BoxWeight() {
super();
weight = -1;
}
BoxWeight(double len) {
super(len);
weight = len;
}
}
public class SuperKeywordExample {
public static void main(String[] args) {
double volume, weight;
BoxWeight myBox = new BoxWeight(10, 20, 33.2, 12.10);
BoxWeight myBox1 = new BoxWeight(myBox);
volume = myBox1.volume();
weight = myBox1.weight;
System.out.println("myBox1: volume: " + volume + " weight: " + weight);
BoxWeight myBox2 = new BoxWeight();
volume = myBox2.volume();
weight = myBox2.weight;
System.out.println("myBox2: volume: " + volume + " weight: " + weight);
}
}