作者taco0827 (蛋爷-我爱好人卡)
看板java
标题[问题] 深入浅出JAVA的范例看不懂
时间Tue Jan 20 19:58:54 2015
各位大大好:
求救一下,关於深入浅出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://webptt.com/cn.aspx?n=bbs/java/M.1421755137.A.63E.html
1F:推 mabinogi805: playIt()里就只有那一行程式码啊… 01/20 20:34
2F:推 cyclone350: 因为你少打了 one.playIt() 跟 three.playIt() 01/20 20:40
呃,我的意思是,书页下方有一段话「将右方的空白处填上main()执行完毕後
的物件值。」,但是程式码就这两段,应该也就两个CLASS,
并没有书上所说的什麽三个不同物件值,所以我的疑惑在这边...
3F:→ ssccg: 书上指的应该是 ...three.rating = 127;}结束後,one、two 01/20 21:13
4F:→ ssccg: 、three三个物件(记忆体中)的栏位值,没有说会印出来 01/20 21:13
5F:→ ssccg: 是要练习(?)trace code,不是叫你看output 01/20 21:14
呃,书上还没教到这个,那请问物件值应该如何得知?
※ 编辑: taco0827 (114.44.121.96), 01/20/2015 21:40:35
6F:推 tubbysong: "Playing the movie" 改成self.title 01/21 23:37
7F:→ tubbysong: 修正Self应该是this(指自己 01/21 23:41
8F:推 bsd44lite: 你的问题在於,什麽是class,什麽是object,什麽是inst 01/22 04:22
9F:→ bsd44lite: ance没搞懂 。 01/22 04:22
10F:推 bsd44lite: 书前面一定有说,你没有去搞懂。去重读前面的部份。 01/22 04:26
11F:推 bsd44lite: 不要随便翻过去就算有读了。 01/22 04:29
12F:推 bsd44lite: 我觉得 如果MovieTestDrive 每一行叫你解释是什麽意思 01/22 04:33
13F:→ bsd44lite: 你应该答不出来。 01/22 04:33