首页 > 解决方案 > 在 CanFly 接口中,必须使用一个 CanFly 类型的参数声明 speed 方法

问题描述

在 CanFly 接口中,必须使用一个 CanFly 类型的参数和一个 Double 类型的返回值来声明 speed 方法。参数不知道写什么

public class Solution {
    public static void main(String[] args) throws Exception {
    }

    interface CanMove{
        Double speed();
    }

    interface CanFly extends CanMove{
        @Override
        public Double speed();  
    }
}

标签: java

解决方案


你完全按照任务告诉你的去做。您添加一个带有类型的参数CanFly并返回一个Double对象。

public class Solution {
    public static void main(String[] args) throws Exception {
    }

    interface CanMove{
        Double speed();
    }

    interface CanFly extends CanMove{
       public Double speed(CanFly target);  
    }
}

请记住,您必须删除注释,因为您从接口@Override为现有speed()方法提供了新的重载。CanMove


推荐阅读