帮忙解答下这题。。。。
时间:2011-12-24
来源:互联网
求讲解 谢谢了
Question No: 5
interface MyInterface{}
public class MyInstanceTest implements MyInterface{
static String s;
public static void main(String args[]){
MyInstanceTest t = new MyInstanceTest();
if(t instanceof MyInterface){
System.out.println("I am true interface");
}else {
System.out.println("I am false interface");
}
if(s instanceof String){
System.out.println("I am true String");
}else {
System.out.println("I am false String");
}
}
}
A.compile time error
B.runtime error
C.prints: “I am true interface” followed by “I am true String”
D.prints: “I am true interface” followed by “I am false String”
E.prints: “I am false interface” followed by “I am false String”
F.prints: “I am false interface” followed by “I am true String”
Question No: 5
interface MyInterface{}
public class MyInstanceTest implements MyInterface{
static String s;
public static void main(String args[]){
MyInstanceTest t = new MyInstanceTest();
if(t instanceof MyInterface){
System.out.println("I am true interface");
}else {
System.out.println("I am false interface");
}
if(s instanceof String){
System.out.println("I am true String");
}else {
System.out.println("I am false String");
}
}
}
A.compile time error
B.runtime error
C.prints: “I am true interface” followed by “I am true String”
D.prints: “I am true interface” followed by “I am false String”
E.prints: “I am false interface” followed by “I am false String”
F.prints: “I am false interface” followed by “I am true String”
作者: aesir2012 发布时间: 2011-12-24
虽然格式很乱,但是还是耐着性子看到了if(s instanceof String)这一行,编译错误,A
没有继承、实现关系的类是无法instanceof的
没有继承、实现关系的类是无法instanceof的
作者: ticmy 发布时间: 2011-12-24
D s 被初始化为 null。 null instanceof XXX 总是 false
作者: huntor 发布时间: 2011-12-24
我被打败了,原来s是String类型的。。。。坑爹啊
引用 1 楼 ticmy 的回复:
虽然格式很乱,但是还是耐着性子看到了if(s instanceof String)这一行,编译错误,A
没有继承、实现关系的类是无法instanceof的
虽然格式很乱,但是还是耐着性子看到了if(s instanceof String)这一行,编译错误,A
没有继承、实现关系的类是无法instanceof的
作者: ticmy 发布时间: 2011-12-24
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28