我有以下code.I無法理解它是關於傳遞值的行爲。值傳遞給java中的變量
class Box{
int length=5;
int height=5;
int width=10;
void volume(){
int volume;
volume=length*height*width;
System.out.println(volume);
}
}
public class DemoBox {
public static void main(String[] args){
Box ob=new Box();
ob.length=10;
ob.height=10;
ob.width=10;
ob.volume();
}
}
這提供了1000的輸出。爲什麼它不是250?值如何分配給變量?
謝謝@ tanveer ..我明白了。我是java的新手。所以我必須學習更多:) – Dinesha