0

这是我的代码:

public void start()
{
  //If the gas tank and oil have more than nothing, and the transmission is in gear park, then the car can start
  if((gasTank.getGasLevel() > 0) && (engine.getOilLevel() > 0) && (transmission.gearPark()))
  {
    engine.startEngine();
    System.out.println("Engine is now on");
  }
  else
  {
    System.out.println("Please make sure your car is in proper gear, engine has oil and gas.");
  }
}

我不断收到'void' type not allowed here错误。我不想返回任何东西,所以我知道我不需要 int、Boolean、double 等。

我究竟做错了什么?

4

2 回答 2

7

您的代码不在类中。

试试这个:

public class SomeClass {
    // your method here
}
于 2013-02-22T08:27:08.777 回答
1

看起来这些方法中的一种或多种可能是无效的,但不能是:

getGasLevel(); 
getOilLevel();
gearPark()

它们不能是无效的,因为您在 if 语句中检查从它们返回的值。

于 2013-02-22T08:25:26.807 回答