4 回答

TA贡献104条经验 获得超33个赞
应该不考虑java8。
void setTime(int time);//接口没有方法体
public class MyProgram implements Sleepable{ //实现接口
@Override
public void setTime(int time){}
}

TA贡献41条经验 获得超26个赞
如果是java8的话,可以这样修改:
interface Sleepable {
final static int MAX = 100;
default void setTime(int time) {};
}
public class MyProgram implements Sleepable {
public static void main(String[] args) {
System.out.println("Hello");
}
}
其他情况可以直接将interface改成class就行了:
class Sleepable {
final static int MAX = 100;
void setTime(int time) {};
}
public class MyProgram extends Sleepable {
public static void main(String[] args) {
System.out.println("Hello");
}
}

TA贡献3593条经验 获得超1个赞
添加回答
举报