【发布时间】:2020-05-18 17:29:42
【问题描述】:
我想从超类继承特定实例,而不是全部。
例如:
public class Snake extends Reptile {
private boolean hasLegs = false;
public Snake(double[] legLength, double tailLength, String color, boolean hasScales, boolean hasLegs) {
super(legLength, tailLength, color, hasScales);
this.hasLegs = hasLegs;
}
我想从类Reptile 继承所有实例变量,除了double[] legLength(因为蛇没有腿)。
如何在不更改 Reptile 类中的代码的情况下做到这一点?
谢谢。
【问题讨论】: