JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java SE 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) [Re:Yoshi]
T55555

Java, Ruby, Haskell

版主

發文: 1026
積分: 24
於 2003-09-15 02:16 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
dup = duplicate, why to do that ... etc
check the java bytecode explanation.
( if you are interesting in bytecode stuff. BTW there are also bytecode compiler, you can program java by bytecode instructions :) )

This is clasic problem, order is important, method override is important
(expectially, method override is be called by constructor) ... etc
"Thinking in Java" already point out longtime ago.

Here is my example to show you more clear what happen...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class A {
  public static A a = new A();
  public static int i = 5;
  public A() {
    System.out.println(a);
    System.out.println(i);
  }
  public void print() {
    System.out.println(a);
    System.out.println(i);
  }
  public static void main(String[] args) {
    A.a.print();
  }
}

See the output result, and you know what's going wrong...
It is kind of like you are written the example like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public class A {
  public static A a;  // declare, and by default init to null
  public static int i; // declare, and by default init to zero
  static {
    a = new A();  // change the a
    i = 5;            //  change the i
  }
  public A() {
    System.out.println(a);
    System.out.println(i);
  }
  public void print() {
    System.out.println(a);
    System.out.println(i);
  }
  public static void main(String[] args) {
    A.a.print();
  }
}

And for the overriden method problem, there are sure examples on Thinking in Java, I want not say more.


T55555 edited on 2003-09-15 02:23
reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
12240 [精華] [轉錄]全世界所有程式員都會犯的錯誤(初始化) Yoshi 3886 2003-09-14 19:23
9863 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) UndeadJ 1000 2003-09-14 23:40
10204 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) T55555 1133 2003-09-15 00:43
9481 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) UndeadJ 111 2003-09-15 01:29
10167 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) T55555 1500 2003-09-15 02:16
9450 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) Yoshi 307 2003-09-15 16:10
9258 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) UndeadJ 134 2003-09-15 17:17
9310 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) Yoshi 131 2003-09-15 17:22
9287 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) UndeadJ 338 2003-09-15 17:46
9269 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) Yoshi 288 2003-09-15 17:54
9287 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) UndeadJ 237 2003-09-15 17:55
9319 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) UndeadJ 13 2003-09-15 02:33
9363 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) T55555 1013 2003-09-15 21:18
10164 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) Duncan 2561 2003-09-15 22:55
9252 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) Yoshi 247 2003-09-16 02:30
9181 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) Yoshi 537 2003-09-16 02:40
9210 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) T55555 1008 2003-09-16 03:04
9253 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) T55555 928 2003-09-16 03:14
9271 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) Yoshi 198 2003-09-16 03:29
9859 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) Duncan 3196 2003-09-16 11:03
9586 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) T55555 1135 2003-09-16 22:42
9688 Re:[轉錄]全世界所有程式員都會犯的錯誤(初始化) Duncan 256 2003-09-17 01:31
» JWorld@TW »  Java SE 討論區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8