帮我看看,哪里有错

liuleyiusst 2010-04-07 02:25:06
class Student {

private String name;
private int age;
private int number;

public Student(String name, int age, int number) {
this.name = name;
this.age = age;
this.number = number;
}

public void setStudent(String _name, int _age, int _number) {
name = _name;
age = _age;
number = _number;
}

public void display() {
System.out.println(name + " - " + age + " - " + number);
}
}

public class Stu {

public static void main(String[] args) {
Student student = new Student(liu, 20, 1);

student.display();
student.setStudent(chen, 20, 2);
student.display();

}
}
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
symbol: variable liu
location: class stu.Stu
at stu.Stu.main(Stu.java:37)
Java Result: 1
...全文
142 9 打赏 收藏 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
copysimles 2010-04-07
  • 打赏
  • 举报
回复
终于有一个帖子我看得明白的了
lqw521326 2010-04-07
  • 打赏
  • 举报
回复
UP UP UP UP UP
z812183667 2010-04-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lijianjian578286 的回复:]
你用记事本写的?
Student student = new Student(liu, 20, 1);
liu为字符串"liu"
[/Quote]
顶!
liuleyiusst 2010-04-07
  • 打赏
  • 举报
回复
谢谢大家
keeya0416 2010-04-07
  • 打赏
  • 举报
回复

public class Stu {

public static void main(String[] args) {
Student student = new Student(liu, 20, 1);//liu-->"liu"

student.display();
student.setStudent(chen, 20, 2); //这里也是 "chen"
student.display();

}

davis_rly 2010-04-07
  • 打赏
  • 举报
回复
public static void main(String[] args) {
Student student = new Student(liu, 20, 1); 错了 因为定义了String name,所以需要把liu需用“”才是一个字符串
霜之哀伤 2010-04-07
  • 打赏
  • 举报
回复
Student student = new Student(liu, 20, 1);

错误信息说的很明白了啊
liu 没有定义过。
改成"liu"
@井九 2010-04-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lijianjian578286 的回复:]
你用记事本写的?
Student student = new Student(liu, 20, 1);
liu为字符串"liu"
[/Quote]
up
jacky花园 2010-04-07
  • 打赏
  • 举报
回复
你用记事本写的?
Student student = new Student(liu, 20, 1);
liu为字符串"liu"

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧