接口

接口

接口 

接口 

接口 

接口 

package cn.implement;

public class Demo2Interface {
    public static void main(String[] args) {
        Cat cat = new Cat();

        method(cat);
        Dog dog = new Dog();
        method(dog);
    }
    public static void method(Cat cat)
    {
        cat.sleep();
        cat.eat();
    }
    public static void method(Dog dog)
    {
        dog.eat();
        dog.sleep();
    }
}

 

 

 

package cn.implement;

public class Demo3Interface {
    public static void main(String[] args) {
        Cat cat = new Cat();

        method(cat);
        Dog dog = new Dog();
        method(dog);
    }
    public static void method(Animal animal)
    {
        animal.sleep();
        animal.eat();
    }

}

接口