【发布时间】:2013-11-25 23:59:53
【问题描述】:
public class This_testing {
int x,y;
public This_testing(int x,int y){ //Why modifier void here would cause exception?
this.x=x;
this.y=y;
}
public static void main(String [] args){
This_testing t =new This_testing(40,50);
System.out.println(t.x+" "+t.y);
}
}
为什么对构造函数 This_testing 使用修饰符 void 会导致以下异常:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code -
constructor This_testing in class practice.This_testing cannot be applied to given types;
required: no arguments
found: int,int
reason: actual and formal argument lists differ in length
at practice.This_testing.main(This_testing.java:13)
【问题讨论】:
-
与您的问题无关,但
x=x;行没有任何作用。 -
@DavidWallace:谢谢
标签: java constructor modifier