Java Multiple Inheritance

前端 未结 17 1310
猫巷女王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:19

    you can have an interface hierarchy and then extend your classes from selected interfaces :

    public interface IAnimal {
    }
    
    public interface IBird implements IAnimal {
    }
    
    public  interface IHorse implements IAnimal {
    }
    
    public interface IPegasus implements IBird,IHorse{
    }
    

    and then define your classes as needed, by extending a specific interface :

    public class Bird implements IBird {
    }
    
    public class Horse implements IHorse{
    }
    
    public class Pegasus implements IPegasus {
    }
    

提交回复
热议问题