forked from akash-coded/C133-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInheritance.java
77 lines (58 loc) · 1.3 KB
/
Inheritance.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
class Grandparent {
int a = 10;
Grandparent() {
}
// Grandparent(String msg) {
// System.out.println("This is the Grandparent class. " + msg);
// }
void run() {
System.out.println("I am from the 60s");
}
}
class Parent extends Grandparent {
int b = 20;
Parent() {
}
// Parent(double x, String msg) {
// // super(msg);
// System.out.println(x);
// }
@Override
public void run() {
System.out.println("I am from the 80s");
// super.run();
}
void show() {
System.out.println("I am from parent class");
}
}
class Child extends Parent {
int c = 30;
Child() {
}
// Child(int x, double y, String z) {
// super(y, z);
// System.out.println(x);
// }
@Override
public void run() {
System.out.println("I am a millenial");
// super.run();
}
// void show() {
// System.out.println("I am from child class");
// // super.show();
// }
void watch() {
System.out.println("I belong to the digital era");
}
}
public class Inheritance {
public static void main(String[] args) {
Grandparent g = new Grandparent();
Parent p = new Child();
p.run();
p.show();
// ((Child) p).watch();
}
}