[問題] 深入淺出JAVA的範例看不懂

作者: taco0827 (蛋爺-我愛好人卡)   2015-01-20 19:58:54
各位大大好:
求救一下,關於深入淺出JAVA第二版這本書,看到第37頁,
遇到一個難題,(書頁快照:
)
我寫了一個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撰寫
作者: mabinogi805 (焚離)   2015-01-20 20:34:00
playIt()裡就只有那一行程式碼啊…
作者: cyclone350 (老子我最神)   2015-01-20 20:40:00
因為你少打了 one.playIt() 跟 three.playIt()
作者: ssccg (23)   2015-01-20 21:13:00
書上指的應該是 ...three.rating = 127;}結束後,one、two、three三個物件(記憶體中)的欄位值,沒有說會印出來是要練習(?)trace code,不是叫你看output
作者: tubbysong (song)   2015-01-21 23:37:00
"Playing the movie" 改成self.title修正Self應該是this(指自己
作者: bsd44lite (無心插柳柳橙汁)   2015-01-22 04:22:00
你的問題在於,什麼是class,什麼是object,什麼是instance沒搞懂 。書前面一定有說,你沒有去搞懂。去重讀前面的部份。不要隨便翻過去就算有讀了。我覺得 如果MovieTestDrive 每一行叫你解釋是什麼意思你應該答不出來。

Links booklink

Contact Us: admin [ a t ] ucptt.com