-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.java
More file actions
46 lines (37 loc) · 904 Bytes
/
Main.java
File metadata and controls
46 lines (37 loc) · 904 Bytes
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
class A {
// Constructor of A
A() {
System.out.println("A constructor called");
}
void show() {
System.out.println("This is class A");
}
}
class B extends A {
// Constructor of B
B() {
System.out.println("B constructor called");
}
void show() {
System.out.println("This is class B");
}
}
class C extends B {
// Constructor of C
C() {
System.out.println("C constructor called");
}
void show() {
System.out.println("This is class C");
}
}
public class Main {
public static void main(String[] args) {
A a = new A(); // calls A() constructor
B b = new B(); // calls A() then B()
C c = new C(); // calls A() then B() then C()
a.show(); // A's show()
b.show(); // B's show()
c.show(); // C's show()
}
}