If I have an abstract class with the following function -
abstract class A{
void foo(String s) throws Exception{
throw new Exception("exception!");
}
}
And then another class that extends the abstract class and implements its own version of foo -
class B extends A{
void foo(String s){
//do stuff that does *not* throw an exception
}
}
Will this create problems? Specifically in the following test case -
Collection<A> col = new Collection<A>();
B b = new B();
col.add(b);
for(A a : col){
a.foo();
}
I did some testing and nothing seems to have broken, but I don't understand why B's foo was called and not A's
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…