JAVA需要标识符,,怎么办

来源:百度知道 编辑:UC知道 时间:2024/06/30 08:55:32
public class Hello{
System.out.println(s);
}

class A
{
public static void main(String args[]){
System.out.println("Hello world!");
}
}
第二行需要标识符,怎么办

public class A改成这样
如果你的两个类是在一个文件里面 那么把Hello的public修饰符去掉

因为一个文件最多只能有一个public类 而且你想运行main函数这个public类 类名必须和文件名相同 看看你的类满足这两个条件吗?

程序不对。

如下:
public class Hello{
String a = "";

public Hello(String s) {
a = s;
}

public void test() {
System.out.println(a);
}

public static void main(String args[]){
Hello hello = new Hello("Hello world!");
hello.test(hello);
}
}

你应该这么写吧
System.out.println("s");