通过内部类的方式-JAVA变相实现多继承(Through the way of internal classes – Java to realize multi inheritance in disguise)

package com.algorithm;

public class Animal {

    class Cat {
       public void say(){
           System.out.println("小猫喵喵叫");
       }
       public void run(){
           System.out.println("小猫跑跑跑");
       }
       public void jump(){
           System.out.println("小猫跳跳跳");
       }



    }
    class Dog {
        public void say(){
            System.out.println("小狗旺旺叫");
        }
        public void run(){
            System.out.println("小狗跑跑跑");
        }
        public void jump(){
            System.out.println("小狗跳跳跳");
        }

    }

}
package com.algorithm;

public class Mammal extends Animal  {
    public static void main(String[] args) {
        Mammal mammal = new Mammal();
        Dog dog = mammal.new Dog();
        dog.say();
        dog.run();
        dog.jump();
        Cat cat = mammal.new Cat();
        cat.say();
        cat.run();
        cat.jump();
    }
}

运行结果:

小狗旺旺叫小狗跑跑跑小狗跳跳跳小猫喵喵叫小猫跑跑跑小猫跳跳跳

————————
package com.algorithm;

public class Animal {

    class Cat {
       public void say(){
           System.out.println("小猫喵喵叫");
       }
       public void run(){
           System.out.println("小猫跑跑跑");
       }
       public void jump(){
           System.out.println("小猫跳跳跳");
       }



    }
    class Dog {
        public void say(){
            System.out.println("小狗旺旺叫");
        }
        public void run(){
            System.out.println("小狗跑跑跑");
        }
        public void jump(){
            System.out.println("小狗跳跳跳");
        }

    }

}
package com.algorithm;

public class Mammal extends Animal  {
    public static void main(String[] args) {
        Mammal mammal = new Mammal();
        Dog dog = mammal.new Dog();
        dog.say();
        dog.run();
        dog.jump();
        Cat cat = mammal.new Cat();
        cat.say();
        cat.run();
        cat.jump();
    }
}

Operation results:

The dog Wangwang calls the dog to run, run, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump, jump