OOP继承扩展
OOP Inheritance Extends
只有 运行 在 Get Phase 中有一篇摘要。我真的不知道为什么,天哪?
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);
}
}
不是 运行宁它说:
Bus is not abstract and does not override abstract method VCapacity() in Vehicle
public class Bus extends Vehicle
当您扩展 abstract
class 时,您需要覆盖父 class 中定义的方法。
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
中不接收参数。
只有 运行 在 Get Phase 中有一篇摘要。我真的不知道为什么,天哪?
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);
}
}
不是 运行宁它说:
Bus is not abstract and does not override abstract method VCapacity() in Vehicle
public class Bus extends Vehicle
当您扩展 abstract
class 时,您需要覆盖父 class 中定义的方法。
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
中不接收参数。