求一道关于JAVA 中class extend的选择题

来源:百度知道 编辑:UC知道 时间:2024/06/24 18:29:36
希望能给出正确答案的解释,谢谢!难度中等即可

public class Test{
public static Foo f=new Foo();
public static Foo f2;
public static Bar b=new Bar();
public static void main(String arg0[]){
for(int x=0;x<6;x++){
f2=getFoo(x);
f2.react();
}
}
static Foo getFoo(int y){
if(0==y%2){
return f;
}else{
return b;
}
}
}
class Bar{
void react(){System.out.println("Bar");}
}
class Foo extends Bar{
void react(){System.out.println("Foo");}
}
what is the result?
A.Bar Bar Bar Bar Bar Bar
B.Foo Bar Foo Bar Foo Bar
C.Foo Foo Foo Foo Foo Foo
D.Compilation fa