假设我们有以下代码:
public interface Dvd {
void startDvd();
}
Run Code Online (Sandbox Code Playgroud)
和另一个接口:
public interface Tv {
void startTv();
}
Run Code Online (Sandbox Code Playgroud)
和一个类:
public class Logitech implements Dvd, Tv {
@Override
public void startDvd() {
}
@Override
public void startTv() {
}
}
Run Code Online (Sandbox Code Playgroud)
然后当你创建一个实例时:
public class Demo {
public static void main(String[] args) {
Tv tv = new Logitech();
tv. //here when we click the . we expect to see only the startTv()
//method, as the type of our reference is Tv
}
}
Run Code Online (Sandbox Code Playgroud)
然而显示的是: