嘿,我正在學習java我寫了這個簡單的代碼,我找不到任何錯誤。我無法獲得Bike2 .getTime。感謝閱讀爲什麼Bike2.getTime()返回0而不是正確的整數值?
public class ConstructorEx3 {
int Speed;
int Distance;
int Minute;
public int getTime(){
return ((Distance/Speed)*Minute);
}
ConstructorEx3(){
Distance = 60;
Speed = 30;
Minute = 60;
}
ConstructorEx3 (int D, int S, int M){
Distance = D;
Speed = S;
Minute = M;
}
public static void main (String []arsh){
ConstructorEx3 Bike1,Bike2;
Bike1 = new ConstructorEx3();
Bike2 = new ConstructorEx3(40,80,60);
System.out.println("Bike one is travelling at : "+ Bike1.getTime());
System.out.println("Bike two is travelling at : "+ Bike2.getTime());
}
}
你是什麼意思「我不能讓Bike2.getTime()' – Stultuske
請實際上? *描述*這個問題,不要以爲我們知道這段代碼應該在做什麼或者你在運行時看到了什麼 – David
@ bcsb1001:它在構造函數上方 – Stultuske