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 fails
E.An exception is thrown at runtime请大家给个答案和理由
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 fails
E.An exception is thrown at runtime请大家给个答案和理由
解决方案 »
- java 连接sybase 事物处理 报空指针,请指教
- 正则表达试问题,帮帮我啊,在线等
- Servlet 接收请求如何以秒为单位进行计数 ,怎么实现?(求教高手)
- String和StringBuffer的区别
- 向大家请教一个数据结构算法问题!!
- 请教:我刚才在编译的时候为什么老是:errer cannot read apple_1.java( 这是我的文件名)
- 怎样对一个文件进行随机的读出
- 请问该如何获取环境变量? 谢谢
- Exception in thread "main" java.lang.NoClassDefFoundError: jb
- java里toString方法到底有什么作用呀?
- 求具体算法 Matlab里的interp1()一维插值方法
- javamail如何检查邮件服务器上的邮件地址?
基类Bar不能向下转换Foo
:)
1....getFoo的返回类型更改为Bar并把f2的类型申明为Bar
2....react()都改为静态
请问下结果
基类Bar不能向下转换Foo]同意这个观点
static Foo getFoo(int y){中return b;
基类Bar不能向下转换Foo]同意这个观点