【发布时间】:2020-11-07 20:58:51
【问题描述】:
public interface InterfaceTest {
interface Gift { void present(); }
interface Guest { void present(); }
interface Presentable extends Gift, Guest { }
public static void main(String[] args) {
Presentable johnny = new Presentable() {
@Override public void present() {
System.out.println("Heeeereee's Johnny!!!");
}
};
johnny.present();
((Gift) johnny).present();
((Guest) johnny).present();
Gift johnnyAsGift = (Gift) johnny;
johnnyAsGift.present();
Guest johnnyAsGuest = (Guest) johnny;
johnnyAsGuest.present();
}
}
此代码编译并运行 main() 函数没有错误,我这里缺少什么概念?
【问题讨论】:
标签: java interface instantiation bluej