看板 java 關於我們 聯絡資訊
各位大大好: 求救一下,關於深入淺出JAVA第二版這本書,看到第37頁, 遇到一個難題,(書頁快照:http://ppt.cc/~jIG ) 我寫了一個class Movie一個class MovieTestDrive, 可是並沒有書上的object1、2、3們, 怎麼執行都只有一句話"Playing the Movie", 請問這是為什麼呢?? 第一個Class Movie class Movie { String title; String genre; int rating; void playIt(){ System.out.println("Playing the movie"); } } 第二個Class MovieTestDrive public class MovieTestDrive { public static void main(String[] args){ Movie one = new Movie(); one.title = "Gone with the Stock"; one.genre = "Tragic"; one.rating = -2; Movie two = new Movie(); two.title = "Lost in Cubicle Space"; two.genre = "Comeby"; two.rating = 5; two.playIt(); Movie three = new Movie(); three.title = "Byte Club"; three.genre = "Tragic but ultimately uplifting"; three.rating = 127; } } PS:我是用Eclipse撰寫 -- 謝謝妳!妳真是個好人! ( ′▽`)-o█ 集滿一本可以來跟我換 神秘小禮物呦~ (羞~) http://ppt.cc/xpUq -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.44.121.96 ※ 文章網址: https://www.ptt.cc/bbs/java/M.1421755137.A.63E.html
mabinogi805: playIt()裡就只有那一行程式碼啊… 01/20 20:34
cyclone350: 因為你少打了 one.playIt() 跟 three.playIt() 01/20 20:40
呃,我的意思是,書頁下方有一段話「將右方的空白處填上main()執行完畢後 的物件值。」,但是程式碼就這兩段,應該也就兩個CLASS, 並沒有書上所說的什麼三個不同物件值,所以我的疑惑在這邊...
ssccg: 書上指的應該是 ...three.rating = 127;}結束後,one、two 01/20 21:13
ssccg: 、three三個物件(記憶體中)的欄位值,沒有說會印出來 01/20 21:13
ssccg: 是要練習(?)trace code,不是叫你看output 01/20 21:14
呃,書上還沒教到這個,那請問物件值應該如何得知? ※ 編輯: taco0827 (114.44.121.96), 01/20/2015 21:40:35
tubbysong: "Playing the movie" 改成self.title 01/21 23:37
tubbysong: 修正Self應該是this(指自己 01/21 23:41
bsd44lite: 你的問題在於,什麼是class,什麼是object,什麼是inst 01/22 04:22
bsd44lite: ance沒搞懂 。 01/22 04:22
bsd44lite: 書前面一定有說,你沒有去搞懂。去重讀前面的部份。 01/22 04:26
bsd44lite: 不要隨便翻過去就算有讀了。 01/22 04:29
bsd44lite: 我覺得 如果MovieTestDrive 每一行叫你解釋是什麼意思 01/22 04:33
bsd44lite: 你應該答不出來。 01/22 04:33