对象的转型,注意instanceof是判断是否属于此类或者此类的父类
来源:互联网 发布:善领dsa最新数据 编辑:程序博客网 时间:2024/05/17 07:18
/*
*对象的转型,注意instanceof是判断是否属于此类或者此类的父类
*孔华生
*/
class Animal
{
String name;
Animal(String name)
{
this.name = name;
}
}
class Cat extends Animal
{
String eyeclor;
Cat(String name,String eyeclor)
{
super(name);
this.eyeclor = eyeclor;
}
}
class Dog extends Animal
{
String furclor;
Dog(String name,String furclor)
{
super(name);
this.furclor = furclor;
}
}
public class Testconert
{
public static void main(String[] args)
{
Animal a = new Animal("monkey");
Cat c = new Cat("mimi","white");
Dog d = new Dog("beibei","black");
System.out.println(a instanceof Animal);
System.out.println(c instanceof Animal);
System.out.println(d instanceof Animal);
System.out.println(a instanceof Dog);
a = new Dog("xiaohei","yellow");
System.out.println(a instanceof Animal);
System.out.println(a instanceof Dog);
System.out.println(a.name);
//System.out.println(a.furclor);
Dog d1 = (Dog) a;
System.out.println(d1.furclor);
System.out.println(d1.name);
}
}
*对象的转型,注意instanceof是判断是否属于此类或者此类的父类
*孔华生
*/
class Animal
{
String name;
Animal(String name)
{
this.name = name;
}
}
class Cat extends Animal
{
String eyeclor;
Cat(String name,String eyeclor)
{
super(name);
this.eyeclor = eyeclor;
}
}
class Dog extends Animal
{
String furclor;
Dog(String name,String furclor)
{
super(name);
this.furclor = furclor;
}
}
public class Testconert
{
public static void main(String[] args)
{
Animal a = new Animal("monkey");
Cat c = new Cat("mimi","white");
Dog d = new Dog("beibei","black");
System.out.println(a instanceof Animal);
System.out.println(c instanceof Animal);
System.out.println(d instanceof Animal);
System.out.println(a instanceof Dog);
a = new Dog("xiaohei","yellow");
System.out.println(a instanceof Animal);
System.out.println(a instanceof Dog);
System.out.println(a.name);
//System.out.println(a.furclor);
Dog d1 = (Dog) a;
System.out.println(d1.furclor);
System.out.println(d1.name);
}
}
- 对象的转型,注意instanceof是判断是否属于此类或者此类的父类
- 注意instanceof是判断是否属于此类或者此类的父类----java
- C#实现java instanceof (判断对象是否属于哪个类)
- JAVA判断对象是不是属于哪一个类 instanceof , isInstance ,isAssignableFrom
- Python的特殊类成员6;此需要注意是Python3
- 锁是属于对象或类的
- instanceof 算符是用来在运行时指出对象是否是特定类的一个实例
- 在java中怎么理解“用instanceof操作符判断父类对象是否为子类的一个实例”?
- 此函数用来判断传入的字符串参数是否全是字母数字的组合
- 怎么反驳此类客户,是我的错吗?
- java中原来可以判断对象是否是属于一个类
- is_a 判断一个对像是否属于一个类,或者该类的父类
- js 判断一个对象是否属于某一类
- 【OC学习-15】如何判断两个对象是否属于同一个类?如何判断一个对象是否属于某一个类?
- java判断对象或者对象数组是否为空的类
- 用instanceof判断参数是否是给定的类型
- iOS判断程序是否是第一次安装此APP
- 静态方法和静态变量是属于某一个类,而不属于类的对象
- 读取csv文件数据内容进行图形绘制(vc++描述)
- 多进程的编程实例
- 各类数据库方言
- 求和
- Ajax封装类
- 对象的转型,注意instanceof是判断是否属于此类或者此类的父类
- MongoDB C# / .NET Driver 中IMongoQuery的内部实现Query的用法
- SGU 548 - Dragons and Princesses
- 看完很清醒,我相信这是一个同龄人写的。。加油。。被扇醒的感觉
- 怎样完全用 GNU/Linux 工作
- VC中的_T()与L宏
- 分页封装
- 使用 JXL 读取 excel 出现了 日期截断的问题 (单元格格式:日期-->出现此问题)
- 测试人员必备的数据库知识02