新手求问啊
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("无法进行类型转换");
}
}}