2008-04-12
个人 关于instanceof的认识
最近在看书的过程中,发现JAVA中的instanceof这个关键字与NET中as关键字功能有些
类似,所以就自己写了点东西。
String s = "this is a string";
声明了一个字符串对象。
System.out.println(s instanceof String); //结果 True;
interface Parent{
public String read();
}
public class Son1 extends Parent{
public String read(){
return "I am Your first SON!";
}
}
public class Son2 extends Parent{
public String read(){
return "I am Your second SON!";
}
}
public class Son1 extends Parent{
public void main(String[] arg){
Son1 s1 = new Son1();
Son2 s2 = new Son2();
if(s1 instanceof Parent){
out.println(read());
}
if(s2 instanceof Parent){
out.println(read());
}
}
}
类似,所以就自己写了点东西。
String s = "this is a string";
声明了一个字符串对象。
System.out.println(s instanceof String); //结果 True;
interface Parent{
public String read();
}
public class Son1 extends Parent{
public String read(){
return "I am Your first SON!";
}
}
public class Son2 extends Parent{
public String read(){
return "I am Your second SON!";
}
}
public class Son1 extends Parent{
public void main(String[] arg){
Son1 s1 = new Son1();
Son2 s2 = new Son2();
if(s1 instanceof Parent){
out.println(read());
}
if(s2 instanceof Parent){
out.println(read());
}
}
}
- 13:02
- 浏览 (435)
- 评论 (0)
- 分类: JSP/JAVA学习总结
- 相关推荐
发表评论
- 浏览: 6970 次
- 性别:

- 来自: 上海

- 详细资料
搜索本博客
我的相册
老婆2
共 7 张
共 7 张
最近加入圈子
最新评论
-
今天要做公司内部的一个Or ...
整理成word文档 下来看看 这样看累的 内容挺好的
-- by antonyup_2006 -
高兴呀!得到华为的录取通 ...
你们也太不了解华为了!一个很好的企业,公司很人性化,还有手把手的导师制度。同时业 ...
-- by jzhua2006 -
高兴呀!得到华为的录取通 ...
2个月了,还没有si?
-- by testlga -
公司不能上网,现在就很少 ...
紧张不?一周多久休息啊
-- by flameanger -
公司不能上网,现在就很少 ...
在哪上班呢?
-- by flameanger






评论排行榜