且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我们可以创建抽象类的对象吗?

更新时间:2021-10-29 23:55:35

test 是匿名对象 AbstractTest 的具体子类(请注意,它实现了 AbstractTest 的所有抽象方法),这就是为什么该子类

test is an object of an anonymous concrete sub-class of AbstractTest (note that it implements all the abstract methods of AbstractTest), which is why this sub-class can be instantiated.

另一方面,

AbstractTest test = new AbstractTest();

不会通过编译,因为那是实例化抽象类的尝试。

wouldn't pass compilation, since that would be an attempt to instantiate an abstract class.