1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
public class Example049 { private int overtime; public static Example049 INSTANCE = new Example049(); //1 private static int CURRENT_YEAR = Calendar.getInstance().get( Calendar.YEAR); //2 private Example049() { overtime = CURRENT_YEAR - 1970 ; } public int getOverTime() { return overtime; } public static void main(String[] args) { System.out.println(INSTANCE.getOverTime()); } } |
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
|
//文件1 public class Example051Parent { protected int x; Example051Parent( int x) { this .x = x; output(); } protected void output() { System.out.println(x); } } //文件2 public class Example051Sub extends Example051Parent { String f; Example051Sub( int x, String f) { super (x); this .f = f; } @Override protected void output() { System.out.println(x + "--" + f); } public static void main(String[] args) { new Example051Sub( 1 , "ape_it" ); } } |