-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathFinalField.java
58 lines (45 loc) · 1.48 KB
/
FinalField.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
public class FinalField {
static final int b = calculate();
static final int a = 3;
static final int z = 1 + 2;
static int d = calculate2();
static final boolean c = true;
final int x;
final int y;
static final int i3 = testString();
static final int i4 = testString2();
static final String message = (new FinalField()).toString();
static final String m = "this is a message";
static final String m2 = "this" + " is a " + "message";
private static int calculate2() { return z; }
private static int calculate() { return a; }
private static int testString() { return m.length(); }
private static int testString2() { return m.length(); }
public FinalField(){
System.out.println(this);
x = 3;
System.out.println(this);
y = 4;
System.out.println(this);
}
@Override
public String toString() {
return "(" + x + ", " + y + ")";
}
public static void main(String[] args) {
System.out.println("Printing non-static message");
System.out.println(new FinalField().toString());
System.out.println("---------------------------");
System.out.println(a == b);
System.out.println(z == d);
System.out.println(m);
System.out.println(m == "this is a message");
System.out.println(m == m2);
System.out.println(m2);
}
static {
System.out.println("Printing static message");
System.out.println(message);
System.out.println("-----------------------");
}
}