public class ChildCourses extends Courses {
public String author;
public ChildCourses(String author,String id, String name){
this.author=author;
this.id=id;
this.name=name;
}
}
在类TestChild中:
public void testChild(){
ChildCourses clr=new ChildCourses("辛夷坞","3","在子类型中增加属性");
courses.add(clr);
}
下图是运行结果
泛型集合添加泛型的子类型的对象实例实际上是父类对子类的引用,而子类中的非抽象方法不能被父类引用