以下代码向我返回一条错误消息:"constructor call must be the first statment in a constructor."

我不明白。我的代码中的构造函数是第一条语句。我究竟做错了什么?

public class labelsAndIcons extends JFrame
{
    public labelFrame()
    {
        super( "Testing JLabel" );
    }
}

最佳答案

构造函数名称必须与类名称相同,因此请更改将类名称更改为labelFrame或将构造函数名称更改为labelsAndIcons

示例(请注意,在Java中通常第一个字母是大写字母):

public class LabelFrame extends JFrame {
    public LabelFrame() {
        super( "Testing JLabel" );
    }
}

07-28 02:28
查看更多