-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathStaticBlockAndAbstractClasses.java
More file actions
45 lines (37 loc) · 1.03 KB
/
StaticBlockAndAbstractClasses.java
File metadata and controls
45 lines (37 loc) · 1.03 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
abstract class ParentAbstract {
static final int x;
public static int parentInt = 80713;
static {
x = 5;
System.out.println("Parent static block executed"); // 1
parentInt = 9;
}
ParentAbstract() {
System.out.println("Parent constructor"); // 3
}
public void methodInParent() {
System.out.println("MethodInParent called"); // 5
}
}
class ChildExtending extends ParentAbstract {
static final int x;
public int childInt = 111213;
static {
x = 10;
System.out.println("Child static block executed"); // 2
}
public ChildExtending() {
System.out.println("Child constructor"); // 4
}
public void methodInChild() {
System.out.println("MethodInChild called");
System.out.println(x);
}
}
public class StaticBlockAndAbstractClasses {
public static void main(String[] args) {
ParentAbstract ce = new ChildExtending();
ce.methodInParent();
((ChildExtending) ce).methodInChild();
}
}