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,選擇實現接口方法,就能自動生成方法了。
沒有問題的,你可以重新生成下代碼,或者保存下文件。
父類構造函數調用沒有問題的。