gpt4 book ai didi

Java 多个构造函数,每种构造函数和不同类型都有一个参数

转载 作者:行者123 更新时间:2023-11-30 06:10:19 24 4
gpt4 key购买 nike

<分区>

我遇到了构造函数的问题。

public abstract class ShapeDrawer implements iShapeDrawer {

protected SimpleLine line; // the line to be drawn
protected SimpleOval oval; // the oval to be drawn
protected SimpleTriangle triangle; // the triangle to be drawn
protected SimplePolygon rectangle; // the triangle to be drawn

public ShapeDrawer(SimpleLine line) {
this.line = line;
}

public ShapeDrawer(SimpleOval oval) {
this.oval = oval;
}

public ShapeDrawer(SimpleTriangle triangle) {
this.triangle = triangle;
}

public ShapeDrawer(SimplePolygon rectangle) {
this.rectangle = rectangle;
}
}

当我尝试运行时,它转到第一个构造函数并为每个构造函数抛出错误。

error: incompatible types: SimpleOval cannot be converted to SimpleLine super(oval);

这就是 Oval 类的一点

public class OvalDrawer extends ShapeDrawer implements iShapeDrawer{

public OvalDrawer(SimpleOval oval) {
super(oval);
}
}

我有 SimpleShape 类,它是 SimpleOval、SimpleLine 等的父类,并且具有所有方法。SimpleOval 示例

public class SimpleOval extends SimpleShape {

public SimpleOval(int xStart, int yStart, int xEnd, int yEnd, Color colour, int thickness, ShapeType shapeType) {
super(xStart, yStart, xEnd, yEnd, colour, thickness, shapeType);
}

有什么建议吗?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com