Java实现接口(interface)

标签 java interface implements

这是我尝试实现一个接口(interface)。

我收到以下错误

javac MyCollection.java
./au/edu/uow/Collection/DVDAlbum.java:6: cannot find symbol
symbol: class Album
public class DVDAlbum implements Album{

这是 super 类

package au.edu.uow.Collection;


public interface Album {

    String getMediaType();

    String getTitle();

    String getGenre();

}

这是子类

public class DVDAlbum implements Album{

    private String Title;
    private String Genre;
    private String Director;
    private String Plot;
    private String MediaType;

    public DVDAlbum(String TempTitle, String TempGenre, String TempDirector, String TempPlot){
        Title = TempTitle;
        Genre = TempGenre;
        Director = TempDirector;
        Plot = TempPlot;
    }
    String getMediaType(){
        return MediaType;
    }
    String getTitle(){
        return Title;
    }
    String getGenre(){
        return Genre;
    }
}

http://www.javabeginner.com/learn-java/java-abstract-class-and-interface 这是我使用的引用,但它对我不起作用。

最佳答案

如果您不在声明接口(interface)的同一个包中,则需要导入它:

import au.edu.uow.Collection.Album;

或者使用完整的限定名称:

public class DVDAlbum implements au.edu.uow.Collection.Album{ }

关于Java实现接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12121768/

相关文章:

Java TreeEditor UI 错误

java - 如何在不知道其名称的情况下调用实现某个接口(interface)的类?

php - __autoload 检测并包含接口(interface)

Java 为什么需要实现接口(interface)?

java - java中字符串是如何处理的

java - 面向 Java、.NET 或 Ruby 的 Smalltalk 编译器

c# - C# 中的逆变

java - 将对象列表转换为接口(interface)列表时出错

java - 找出用于在 Java 中实例化模板的类型

java - 如何复制不同接口(interface)实例的行为?