Search code examples
javaoopinheritanceconstructorabstract-class

Why can't we instantiate an abstract class in Java?


I understand:

  1. Since an abstract class is nothing on its own, e.g. vehicle, we want to create an object of an concrete implementation, like Car, Bike, etc.
  2. The constructor of an abstract class gets called during object chaining.
  3. We can never directly create an object of an abstract class, even if it contains a constructor and all methods are implemented.

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


Solution

  • 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.