该类型已在eclipse中定义

时间:2016-08-01 00:48:27

标签: java eclipse

我正在研究关于Java的eclipse我遇到了这样的问题:

这是第一堂课

class Vehicle {
    int passengers;
    int fuelcap;
    int mpg;
}

public class VehicleDemo {

    public static void main(String[] args) {
        Vehicle minivan = new Vehicle();
        int range;

        //assign values to fields in minivan
        minivan.passengers = 7;
        minivan.fuelcap = 16;
        minivan.mpg = 21;

        //compute the range assuming a full tank of gas
        range = minivan.fuelcap * minivan.mpg;
        System.out.println("Minivan can carry " + minivan.passengers + " with a range of " + range);
    }
}

这是第二个:

class Vehicle {
    int passengers;
    int fuelcap;
    int mpg;

    void range() {
        System.out.println("Range is " + fuelcap * mpg);
    }
}

public class AddMeth {

    public static void main(String[] args) {
        Vehicle minivan = new Vehicle();
        Vehicle sportscar = new Vehicle();

        int range1, range2;

        //assign values to fields in minivan
        minivan.passengers = 7;
        minivan.fuelcap = 16;
        minivan.mpg = 21;

        //assign values to fields in sportscar
        sportscar.passengers = 2;
        sportscar.fuelcap = 14;
        sportscar.mpg = 12;

        System.out.println("Minivan can carry " + minivan.passengers + ". ");

        minivan.range(); // display range of minivan

        System.out.println("Sportscar can carry " + sportscar.passengers + ". ");

        sportscar.range();
    }
}

问题是当我在eclipse中工作并删除第二类的前四行时,我仍然遇到void方法的问题。 eclipse如何使用方法处理多个类?

提前谢谢!

0 个答案:

没有答案