对象转型的小例子
来源:互联网 发布:淘宝店铺团队架构 编辑:程序博客网 时间:2024/05/29 02:41
package lin.sxt;
class Dw
{
private String name;
public Dw(){}
public Dw(String name)
{
this.name = name;
}
public String getName()
{
return this.name;
}
}
class Mao extends Dw
{
private String color;
public Mao(){}
public Mao(String name,String color)
{
super(name);
this.color = color;
}
public String getColor()
{
return this.color;
}
}
class Gou extends Dw
{
private String sy;
public Gou(){}
public Gou(String name,String sy)
{
super(name);
this.sy = sy;
}
public String getSy()
{
return this.sy;
}
}
public class ZXtest {
public void test(Dw x)
{
System.out.println(x.getName());
if(x instanceof Mao)
{
Mao x1=(Mao)x;
System.out.println(x1.getColor());
}
if(x instanceof Gou)
{
Gou x2 = (Gou)x;
System.out.println(x2.getSy());
}
}
public static void main(String[] args) {
ZXtest t= new ZXtest();
Dw a=new Dw("aaaa");
Mao b= new Mao("bbbb","red");
Gou c=new Gou("ccccc","haoting");
t.test(a);
t.test(b);
t.test(c);
}
}
- 对象转型的小例子
- 对象转型的例子
- 对象方法的小例子
- 对象的转型
- 关于对象的转型
- 对象的转型
- 对象的转型
- 7、对象的转型
- 对象的转型
- 对象的转型_21
- Java4Android-对象的转型
- 对象的转型
- #java#对象的转型
- java21对象的转型
- 对象的向上转型和向下转型
- 对象的转型(向上向下转型)
- 对象的上转型对象
- 对象的上转型对象
- ASP.NET2.0主题皮肤
- SQL远程数据同步与数据导入的常用方法[原创]
- Loop, data, and MapReduce
- spring 申明事务中的session的打开与关闭
- CB编程中动态更改自定义打印纸张
- 对象转型的小例子
- STL 详解
- DataGrid操作大全和精华
- STL vector 容器介绍
- 标准模板库(STL)学习指南之List容器
- 全新教学方法 软件实训见成效
- 谁能提供一点关于J2EE的资料 最好是Hibernate和Sping的视频
- C 指针解读
- UNIX下的LD_PRELOAD环境变量