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

前端 未结 16 974
挽巷
挽巷 2020-12-08 05:36

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.
相关标签:
16条回答
  • 2020-12-08 06:05

    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.

    0 讨论(0)
  • 2020-12-08 06:07

    Because an abstract class is an incomplete class (incomplete in the sense it contains abstract methods without body and output) we cannot create an instance or object; the same way you say for an interface.

    0 讨论(0)
  • 2020-12-08 06:08

    Because Java restricted it that's why we can not instantiated the abstract class. Because in general scenario abstract means incomplete so we can not make of object of incomplete things.We have to provide the complete implementation of an abstract class in a concrete class. But we cannot create the object of an abstract class.

    0 讨论(0)
  • 2020-12-08 06:10

    An abstract class is not complete! The author marked it abstract to tell you that some implementation is missing in the code. The author has done some of the work, but you must fill in some bits yourself to get it working. The abstract keyword ensures that no one would accidentally initiate this incomplete class.

    Think of repairing a car. Someone has removed the brake pads and is going to replace them in the next day. Now, to prevent someone accidentally driving this car(which has no brakes installed), the mechanic installs a lock on the steering wheel. It's a fail-safe measure.

    0 讨论(0)
  • 2020-12-08 06:11

    You CAN instantiate an abstract class. You only need to provide a concrete subclass.

    0 讨论(0)
  • 2020-12-08 06:13

    What I understand that Abstract classes may contain abstract (empty without implementation) methods. If we instantiate an object and call the empty method, It's not going to work and may cause problem, hence compiler forces this RULE. any further in-sighter ?

    0 讨论(0)
提交回复
热议问题