在“获取”阶段仅运行一个摘要。我真的不知道为什么,天哪?

abstract public class Vehicle {
    public int nWheels = 0;
    public int VCapacity;

    // Set
    public void numWheels(int nWheels) {
        this.nWheels = nWheels;
    }
    public void VCapacity(int VCapacity) {
        this.VCapacity = VCapacity;
    }

    // Get
    public abstract int getWheels();
    public abstract int VCapacity();

    public Vehicle() { }

    public Vehicle(int nWheels, int VCapacity) {
        numWheels(nWheels);
        VCapacity(VCapacity);
    }
}


不运行它说:


总线不是抽象的,并且不会覆盖Vehicle中的抽象方法VCapacity()
公共级公交车扩展车辆

最佳答案

扩展abstract类时,您需要覆盖父类中定义的方法。

public class Bus extends Vehicle {
    public Bus() {
        super(6, 4); // to set capacity use the Vehicle (int nWheels, int VCapacity) constructor
    }

    @Override
    public int VCapacity() {
    }
}


Vehicle中,它不接收参数。

07-27 19:52