多继承

 
 
//多继承,继承father的strong和mother的kind,继承父类和实现接口。
 
 
interface Father
{
    int strong();
}

interface Mother
{
    int kind();
}
class FatherImpl implements Father{
    @Override
    public int strong(){
        return 10;
    }
}
class MotherImpl implements Mother{
    @Override
    public int kind(){
        return 10;
    }

}
class Son extends FatherImpl implements Mother{

    @Override
    public int strong()
    {
        return super.strong()+1;
    }
    @Override
    public int kind()
    {
        return new MotherImpl(){
            @Override
            public int kind(){
                return super.kind()-1;
            }
        }.kind();

    }
}
public class MutiExtends
{
    public static void main(String[] args)
    {
        Son son = new Son();
        System.out.println(son.kind()+" "+ son.strong());
    }

}

猜你喜欢

转载自blog.csdn.net/os2046/article/details/80771924