当前位置: 技术问答>java相关
检测语句错误
来源: 互联网 发布时间:2015-03-13
本文导语: public myPro throws Exception { int x = 0; String str = new(null); myPro(int i) { x = i; } myPro(String myStr) { str = myStr; } //the following constructor is wrong myPro(int i, String myStr) { ...
public myPro throws Exception
{
int x = 0;
String str = new(null);
myPro(int i)
{
x = i;
}
myPro(String myStr)
{
str = myStr;
}
//the following constructor is wrong
myPro(int i, String myStr)
{
this(i);
this(myStr);
}
//the following constructor is also wrong
myPro(String myStr, int i)
{
x = 0;
this(myStr);
}
public void main(){}
}
请各位指出上述两处错误的原因!
{
int x = 0;
String str = new(null);
myPro(int i)
{
x = i;
}
myPro(String myStr)
{
str = myStr;
}
//the following constructor is wrong
myPro(int i, String myStr)
{
this(i);
this(myStr);
}
//the following constructor is also wrong
myPro(String myStr, int i)
{
x = 0;
this(myStr);
}
public void main(){}
}
请各位指出上述两处错误的原因!
|
在一个构造函数内this()方法最多只能有一个且只能在第一行。