- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFieldInitTest.java
More file actions
Latest commit
36 lines (29 loc) · 893 Bytes
/
Copy pathFieldInitTest.java
File metadata and controls
36 lines (29 loc) · 893 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
// test instance fields initialization:
// inline initialization is called
// before user defined constructor initialization
// and instead of default constructor null initialization
importjava.io.*;
publicclassFieldInitTest{
publicstaticvoidmain(Stringargs[]) {
// not initialized: trying to evaluate it
// will trigger a compilation error
Aa1;
System.out.println("");
// inline initialization is takes place before
// user defined constructor initialization
Aa2 = newA();
System.out.println("");
// inline initialization takes place instead of
// default constructor null initialization
Bb = newB();
}
}
classA {
PrintStreami = System.out.printf("inline initialization\n");
A() {
i = System.out.printf("user defined constructor initialization\n");
}
}
classB{
PrintStreami = System.out.printf("inline initialization\n");
}