【23】java统一初始化

 1 class Cup {
2 Cup(int marker) {
3 System.out.println("Cup(" + marker + ")");
4 }
5 void f(int marker) {
6 System.out.println("f(" + marker + ")");
7 }
8 }
9
10 class Cups {
11 static Cup c1;
12 static Cup c2;
13 static {
14 c1 = new Cup(1);
15 c2 = new Cup(2);
16 }
17 Cups() {
18 System.out.println("Cups()");
19 }
20 }
 1 class Mug {
2 Mug(int marker) {
3 System.out.println("Mug(" + marker + ")");
4 }
5 void f(int marker) {
6 System.out.println("f(" + marker + ")");
7 }
8 }
9
10 public class Mugs {
11 Mug c1;
12 Mug c2;
13 {
14 c1 = new Mug(1);
15 c2 = new Mug(2);
16 System.out.println("c1 & c2 initialized");
17 }
18 Mugs() {
19 System.out.println("Mugs()");
20 }
21 public static void main(String[] args) {
22 System.out.println("Inside main()");
23 Mugs x = new Mugs();
24 }
25 }



posted @ 2012-03-20 15:17  Marstar  阅读(230)  评论(0编辑  收藏  举报