【发布时间】:2019-01-29 19:21:58
【问题描述】:
我有扩展 A 类的 B 类。如何在 C 类中编写一个方法,该方法可以接收包含 B 类或 A 类对象的 ArrayList 而无需覆盖?
public class A {
//Some methods here
}
public class B extends A {
//Some methods here
}
public class C {
public Static void main(String[] args){
ArrayList<A> one = new ArrayList<>();
one.add(new A());
ArrayList<B> two = new ArrayList<>();
two.add(new B())
doStuff(one);
doStuff(two);
}
public void doStuff(args){
//go ahead do stuff
}
}
【问题讨论】:
标签: java inheritance multiple-inheritance