class Student {
private String name;
private int age;
public Student(){}
public Student(String name, int age){
this.name = name;
this.age = age;
}
public void show () {
System.out.println(name +"..."+age);
}
public String getName(){
return name;
}
public int getAge(){
return age;
}
}
学生类上面已给出Student
class Demo {
public static void main(String[] args) {
TreeSet<Student> ts = new TreeSet<Student>();
ts.add(new Student("zhangsan", 19));
ts.add(new Student("zhangsan", 19));
ts.add(new Student("lisi", 20));
ts.add(new Student("wangwu", 22));
for (Student s : ts) {
s.show();
}
}
}
问程序是否运行,如果可以运行,结果是什么 |
|