我照着楼主的代码写了一下,顺便补了两个类的代码,运行起来完全没问题,输出的是hash码(ps:如果想通过sop输出内容建议重写toSting函数)- import java.util.*;
- class Test2
- {
- public static void main(String[] args)
- {
- ArrayList<Person> al = new ArrayList<Person>();
- al.add(new Person("abc1"));
- al.add(new Person("abc2"));
- al.add(new Person("abc3"));
- al.add(new Person("abc4"));
- System.out.println(al);
- ArrayList<Student> al1 = new ArrayList<Student>();
- al1.add(new Student("abc1"));
- al1.add(new Student("abc2"));
- al1.add(new Student("abc3"));
- al1.add(new Student("abc4"));
-
- System.out.println(al1);
- }
- }
- class Person
- {
- private String name;
- Person(String str)
- {
- name = str;
- }
- Person()
- {}
- //get函数我不写了……
- }
- class Student extends Person
- {
- private String name;
- Student(String str)
- {
- name = str;
- }
- }
复制代码
你看看是不是有哪里漏写了?
|