这似乎是从接口创建对象;它是如何工作的? [英] This appears to create an object from an interface; how does it work?
本文介绍了这似乎是从接口创建对象;它是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
interface Int {
public void show();
}
public class Test {
public static void main(String[] args) {
Int t1 = new Int() {
public void show() {
System.out.println("message");
}
};
t1.show();
}
}
推荐答案
您正在定义一个实现接口 Int
的匿名类,并立即创建一个 thatAnonymousClassYouJustMade类型的对象代码>.
You're defining an anonymous class that implements the interface Int
, and immediately creating an object of type thatAnonymousClassYouJustMade
.
这篇关于这似乎是从接口创建对象;它是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文