我编写了以下Java代码,运行时它说:“进程以退出代码0完成”,而不是打印totalNumCars()。为什么会这样,我该如何解决?
public class ParkingGarage extends Module5{
public int numAutomobiles;
public int numLargeAutomobiles;
public static int numGarages;
public ParkingGarage(int automobiles, int largeAutomobiles){
numAutomobiles = automobiles;
numLargeAutomobiles = largeAutomobiles;
numGarages++;
}
public void addCars(int newAutomobiles, int newLargeAutomobiles){
numAutomobiles += newAutomobiles;
numLargeAutomobiles += newLargeAutomobiles;
}
public int totalNumCars(){
int totalCars = numLargeAutomobiles + numAutomobiles;
return totalCars;
}
public static void main(String[] args){
ParkingGarage garage1 = new ParkingGarage(5,5);
garage1.addCars(5, 5);
System.out.println("Number of Cars: " + garage1.totalNumCars());
}
}