question for java2

来源:百度知道 编辑:UC知道 时间:2024/05/29 11:54:10
import java.io.*;

public class passTest{
int x;
passTest(int x){
this.x=x;
}
public void passingValue(){
System.out.println("值为"+x);
}
}
class helloworld{
public static void main(String args[])
{
passTest test=new passTest(10);
test.passingValue();

}
}
1 error 报错,错哪了? 请指教
编译环境没得错,是程序的问题,我按你说的把helloworld类调到了前面,还是错

你把这class helloworld{
public static void main(String args[])
{
passTest test=new passTest(10);
test.passingValue();

}
放前面,保存为helloworld.
java
看看是否出错了.

文件名要是passTest.java

错误信息是什么?

println()里边参数都是String型的。
解决:参数为"值为"+Integer.toString(x)