“构造函数不能应用于给定类型”当构造函数具有继承性时 [英] "Constructor cannot be applied to given types" when constructors have inheritance

查看:94
本文介绍了“构造函数不能应用于给定类型”当构造函数具有继承性时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的基类:

abstract public class CPU extends GameObject {
    protected float shiftX;
    protected float shiftY;

    public CPU(float x, float y) {
        super(x, y);
    }

这是其子类之一:

public class Beam extends CPU {
    public Beam(float x, float y, float shiftX, float shiftY, int beamMode) {
        try {
            image = ImageIO.read(new File("/home/tab/Pictures/Beam"+beamMode+".gif"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        this.x = x;
        this.y = y;
        this.shiftX = shiftX;
        this.shiftY = shiftY;
    }

New构造函数突出显示,并显示:

The New constructor is highlighted and it says:

Constructor CPU in class CPU cannot be applied to given types:
required: float, float
found: no arguments

如何解决?

推荐答案

由于错误试图告诉您,您需要将参数传递给基类的构造函数。

As the error is trying to tell you, you need to pass parameters to your base class' constructor.

添加 super( x,y);

这篇关于“构造函数不能应用于给定类型”当构造函数具有继承性时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆