qq_零_14
2015-12-17 22:55
package com.imooc;
public class Initail {
public static void main(String[] args) {
// TODO Auto-generated method stub
/* Dog dog=new Dog();
dog.age=10;
Dog dog2=new Dog();
dog2.age=10;
*/
Dog dog=new Dog();
Animal animal=dog;
Dog dog2=(Dog)animal;
Cat cat=new Cat();
if(animal instanceof Cat){
Cat cat=(Cat)animal;
}else{
System.out.println("无法进行类型转换");
}
}}
package com.imooc;
public class Initail {
public static void main(String[] args) {
// TODO Auto-generated method stub
/* Dog dog=new Dog();
dog.age=10;
Dog dog2=new Dog();
dog2.age=10;
*/
Dog dog=new Dog();
Animal animal=dog;
Dog dog2=(Dog)animal;
Cat cat2=new Cat();
if(animal instanceof Cat){
Cat cat=(Cat)animal;
}else{
System.out.println("无法进行类型转换");
}
}}
这2个段代码的判断结果是一样的
Java入门第二季 升级版
530653 学习 · 6091 问题
相似问题