问题描述
- JAVA 实现接口方法时报错 implement a supertype method
-
public interface MultimediaControl {
public void play();
public void stop();
public void previous();
public void next();
}public class AudioPlayer extends Product implements MultimediaControl {
String audioSpecification;
ItemType mediaType;@Override //The method play() of type AudioPlayer must override or implement a supertype method public void play() { System.out.println("Playing"); } @Override //The method stop() of type AudioPlayer must override or implement a supertype method public void stop() { System.out.println("Stopped"); } @Override //The method previous() of type AudioPlayer must override or implement a supertype method public void previous() { System.out.println("To the previous"); } @Override public void next() //The method next() of type AudioPlayer must override or implement a supertype method{ System.out.println("To the Next"); } public AudioPlayer(String name, ItemType Type) { super(name); //The constructor Product(String) is undefined mediaType = Type; }
}
还有构造函数中调用父类带参构造函数, 父类中的构造函数 :
public Product(String Name) {
name = Name;
serialNumber = currentProductionNumber;
manufacturedOn = new Date();
}
明明有带String参数的构造?为什么会提示这些错误呢
解决方案
我测试过了,没有问题啊,你是用Eclipse自动提示完成实现接口方法的吗?
先定义类实现接口后,使用Eclipse自动提示ctrl+1,选择实现接口方法,就能自动生成方法了。
没有问题的,你可以重新生成下代码,或者保存下文件。
父类构造函数调用没有问题的。
解决方案二:
可以把错误信息发过来看看吗
时间: 2024-11-08 19:21:33