public static void main(String[] args) {
// TODO Auto-generated method stub
Dog dog = new Dog();
Cat cat=new Cat();
Animal animal=dog;
Animal animal1=cat;
if(animal instanceof Dog){
Dog dog2=(Dog)animal;
}else{
System.out.println("无法进行类型转换");
}
if(animal instanceof Cat){
Cat cat1=(Cat)animal1;
}else{
System.out.println("无法进行类型转换");
}
}
}
Ddion
相关分类