Java Multiple Inheritance

前端 未结 17 1552
猫巷女王i
猫巷女王i 2020-11-22 09:36

In an attempt to fully understand how to solve Java\'s multiple inheritance problems I have a classic question that I need clarified.

Lets say I have class Ani

17条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 10:34

    I have a stupid idea:

    public class Pegasus {
        private Horse horseFeatures; 
        private Bird birdFeatures; 
    
       public Pegasus(Horse horse, Bird bird) {
         this.horseFeatures = horse;
         this.birdFeatures = bird;
       }
    
      public void jump() {
        horseFeatures.jump();
      }
    
      public void fly() {
        birdFeatures.fly();
      }
    }
    

提交回复
热议问题