- import java.util.*;
- class Person
- {
- private String name;
- Person(String name)
- {
- this.name = name;
- }
- public String getName()
- {
- return this.name;
- }
- public String toString()
- {
- return "person:"+name;
- }
- }
- class Student extends Person
- {
- Student(String name)
- {
- super(name);
- }
- }
- class Worker extends Person
- {
- Worker(String name)
- {
- super(name);
- }
- }
- class GenericDemo3
- {
- public static void main(String[] args)
- {
- //Student s = new Student();
- TreeSet<Student> ts = new TreeSet<Student>();
- ts.add(new Student("lisi01"));
- ts.add(new Student("lisi02"));
- ts.add(new Student("lisi03"));
- Iterator<Student> it = ts.iterator();
- while (it.hasNext())
- {
- System.out.println(it.next().getName());
- }
- /*Student s = new Student("lisi001");
- System.out.println(s.getName());*/
- }
- }
|
|