为什么我们不能在Java中实例化一个抽象类?

为什么我们不能在Java中实例化一个抽象类?

问题描述:

我了解:


  1. 由于抽象类本身并不是什么,例如车辆,我们想要创建一个具体实现的对象,例如Car,Bike等。

  2. 在对象链接期间调用抽象类的构造函数。

  3. 我们永远不能直接创建抽象类的对象,即使它包含构造函数并且所有方法都已实现。

但是从编译器的角度来看,Java为什么要强制执行这些规则?

But from the compiler's perspective, why does Java enforce these rules?

这不是技术限制,而是(如您指出)是合乎逻辑的。 Java(和许多其他语言)执行各种规则不是因为它们不可能被破坏,而是因为这是该语言的故意组成部分。

This is not a technical limitation, rather (as you have pointed out) a logical one. Java (and many other languages) enforce various rules not because they are impossible to break, but because this is an intentional part of the language.