-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuper_keyword.java
93 lines (85 loc) · 2.15 KB
/
super_keyword.java
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package src.inheritance;
class box {
private double width, height, depth;
box(box b) {
width = b.width;
height = b.height;
depth = b.depth;
}
box(double w, double h, double d) {
width = w;
height = h;
depth = d;
}
box() {
width = -1;
height = -1;
depth = -1;
}
box(double len) {
width = height = depth = len;
}
double volume() {
return width * height * depth;
}
}
class weightBox extends box{
double weight;
weightBox(weightBox w) {
super(w);
weight = w.weight;
}
weightBox(double w, double h, double d, double w1) {
super(w, h, d);
weight = w1;
}
weightBox() {
super();
weight = -1;
}
weightBox(double l, double m) {
super(l);
weight = m;
}
}
class demoSuper {
public static void main(String[] args) {
weightBox b1 = new weightBox(4, 2, 5, 21);
weightBox b2 = new weightBox();
weightBox b3cube = new weightBox(7, 21);
weightBox b4clone = new weightBox(b1);
System.out.println();
System.out.println("Volume of box1 is " + b1.volume());
System.out.println("Weight of box1 is " + b1.weight);
System.out.println();
System.out.println("Volume of box2 is " + b2.volume());
System.out.println("Weight of box2 is " + b2.weight);
System.out.println();
System.out.println("Volume of cube is " + b3cube.volume());
System.out.println("Weight of cube is " + b3cube.weight);
System.out.println();
System.out.println("Volume of clone is " + b4clone.volume());
System.out.println("Weight of clone is " + b4clone.weight);
System.out.println();
}
}
class a1 {
int i;
}
class b1 extends a1 {
int i;
b1(int a,int b) {
super.i = a;
i = b;
}
void display() {
System.out.println("i of superclass: " + super.i);
System.out.println("i of subclass: " + i);
}
}
class superThisDemo {
public static void main(String[] args) {
b1 obj = new b1(7, 2);
obj.display();
}
}