java错误:构造函数调用必须是构造函数中的第一个语句 [英] java error: constructor call must be the first statement in a constructor
本文介绍了java错误:构造函数调用必须是构造函数中的第一个语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码返回一个错误:构造函数调用必须是构造函数中的第一个语句。
The following code returns me an error saying: "constructor call must be the first statment in a constructor."
我得不到它。我的代码中的构造函数是第一个语句。我做错了什么?
I dont get it. The constructor in my code is the first statement. What am I doing wrong?
public class labelsAndIcons extends JFrame
{
public labelFrame()
{
super( "Testing JLabel" );
}
}
推荐答案
构造函数名称必须与类名称相同,因此更改类名称为 labelFrame
或将构造函数名称更改为 labelsAndIcons
。
The constructors name must be the same as the class name, so change either change the class name to labelFrame
or the constructor name to labelsAndIcons
.
示例(请注意,通常第一个字母是java中的大写字母):
public class LabelFrame extends JFrame {
public LabelFrame() {
super( "Testing JLabel" );
}
}
这篇关于java错误:构造函数调用必须是构造函数中的第一个语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文