静态成员
Java中类似静态构造方法的结构,称之为:静态初始化代码块,与之对应的是实例初始化代码块,见下例:
1 public class Program {
2
3 /**
4 * @param args
5 */
6 public static void main(String[] args) {
7 System.out.println(Point.getValue());
8 System.out.println(new Point());
9 }
10 }
11
12 class Point {
13 private static int value = 0;
14
15 public static int getValue() {
16 return value;
17 }
18
19 static {
20 value++;
21 }
22
23 static {
24 value++;
25 }
26
27 private int x = 0;
28 private int y = 0;
29
30 {
31 this.x = 10;
32 }
33
34 {
35 this.y = 10;
36 }
37
38 public String toString() {
39 return "(x:" + this.x + ",y:" + this.y + ")";
40 }
41 }
继承继承使用 extends,抽象类和抽象方法使用abstract声明,向下转型使用 (ChildType)instance,判断是否是某个类型使用 instanceof,见下例: