[問題] class global 參數宣告處使用new class的問題

看板java作者 (stellvia)時間13年前 (2011/01/04 15:40), 編輯推噓0(003)
留言3則, 1人參與, 最新討論串1/1
我不知道怎麼說比較清楚 程式碼如下 class test02 { test02() { System.out.print("test02\n"); } } public class test01 { test01() { System.out.print("test01\n"); } test02 t02 = new test02(); public static void main(String[] argv) { test01 t01 = new test01(); } } 我在class test01 中 ,寫了這一行test02 t02 = new test02(); (1)那麼test01 class 跟 test02 class 的關係是啥? (2)在main中應該是不能使用 t02物件的對吧 (3)再來t01 跟 t02 應該是屬於不同process吧! 感恩 謝謝!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.130.36.2

01/04 19:11, , 1F
回答(3):是同一個
01/04 19:11, 1F

01/04 19:13, , 2F
回答(2)不可以,但你宣告成static就可以
01/04 19:13, 2F

01/04 19:17, , 3F
(1):看不懂你要問啥關系,如果是OO的觀念就是都沒關係
01/04 19:17, 3F
文章代碼(AID): #1D8iy5_K (java)