package _06_多态综合练习;

public class Person {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

//    public void keepPet(Dog dog , String something){
//        System.out.println("年龄为:"+this.age+"的"+this.name+
//                "养了一只"+dog.getColor()+"的" +dog.getAge() +"岁的狗");
//
//        System.out.println(dog.getAge()+"岁的"+ dog.getColor()+"的"+ dog.eat(something));
//    }
//
//
//    public void keepPet(Cat cat,String something){
//        System.out.println("年龄为:"+this.age+"的"+this.name+
//                "养了一只"+cat.getColor()+"的" +cat.getAge() +"岁的猫");
//        System.out.println(cat.getAge()+"岁的"+ cat.getColor()+"的"+ cat.eat(something));
//    }

    public void keepPet(Anmail anmail, String something){
        // 判断宠物类型是什么类型
        if(anmail instanceof Dog){
            Dog dog = (Dog) anmail;
            System.out.println("年龄为:"+this.age+"的"+this.name+
                    "养了一只"+dog.getColor()+"的" +dog.getAge() +"岁的狗");

            System.out.println(dog.getAge()+"岁的"+ dog.getColor()+"的"+ dog.eat(something));
        }else if(anmail instanceof Cat){
            Cat cat= (Cat) anmail;
            System.out.println("年龄为:"+this.age+"的"+this.name+
                    "养了一只"+cat.getColor()+"的" +cat.getAge() +"岁的猫");
            System.out.println(cat.getAge()+"岁的"+ cat.getColor()+"的"+ cat.eat(something));
        }else{
            System.out.println("其他宠物吃东西");
        }
    }
}
