[问题] 深入浅出JAVA的范例看不懂

楼主: taco0827 (蛋爷-我爱好人卡)   2015-01-20 19:58:54
各位大大好:
求救一下,关于深入浅出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撰写
作者: 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