[問題] 關於return
這是一個小程式
lass Study{
int credit=0;
void addcredit(int i){credit +=i;}
int totalcredit() {return credit;}
}
class E31{
public static void main(String[] agrs){
Study joe=new Study();
joe.addcredit(12);
joe.addcredit(6);
System.out.print("joe study:"+joe.totalcredit());
}
}
但是我將最後一個輸出改成
System.out.print("joe study:"+joe.credit)
兩個結果是一樣的
請問這兩個有什麼差別?
書上是說傳回值,
但是這值回值是傳到哪?
有沒有人可以具體解釋一下
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.143.155.124
推
01/21 22:53, , 1F
01/21 22:53, 1F
→
01/21 22:56, , 2F
01/21 22:56, 2F
→
01/21 22:57, , 3F
01/21 22:57, 3F
→
01/21 22:59, , 4F
01/21 22:59, 4F
→
01/21 23:00, , 5F
01/21 23:00, 5F
→
01/21 23:04, , 6F
01/21 23:04, 6F
推
01/21 23:23, , 7F
01/21 23:23, 7F