toString()问题
学校作业:
编写Java应用程序,封装一个Student类的对象。其中定义一个表示学生的类Student,包括学号、班级、性别、年龄属性,以及获得学号、获得性别、获得性别、获得姓名、获得年龄、修改年龄方法。另加一个public String toString()方法把Student类对象的所有信息组成一个字符串,并有检测这个功能的程序体现。
使用上题编写的Student类创建5个学生对象,并在控制台把5个学生的信息显示出来。
我的代码:
package homework;
public class Student {
String name;
int id;
String ClassNum;
String sex;
int age;
public Student(String name,int id,String ClassNum,String sex,int age){
this.name=name;
this.id=id;
this.ClassNum=ClassNum;
this.sex=sex;
this.age=age;
}
public String getName(){
return this.name;
}
public int getId(){
return this.id;
}
public String getClassNum(){
return this.ClassNum;
}
public String getSex(){
return this.sex;
}
public int getAge(){
return this.age;
}
public void setAge(int age){
this.age=age;
}
public String toString(){
return "My name is "+name+".My id is"+id+".My ClassNum is"+ClassNum+".My sex is"+sex+".My age is"+age+".";
}
Student a=new Student("ZhangSan",123,"class1","boy",11);
Student b=new Student("LiSi",1234,"class1","boy",11);
Student c=new Student("WangWu",12345,"class2","boy",11);
Student d=new Student("MingMing",54321,"class2","girl",12);
Student e=new Student("XingXing",4321,"class3","girl",12);
Student f=new Student("QingQing",321,"class3","girl",12);
System.out.priltln(a);
System.out.priltln(b);
System.out.priltln(c);
System.out.priltln(d);
System.out.priltln(e);
System.out.priltln(f);
}
画下划线是显示错误的地方。
请问要如何显示5个学生的信息???