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

前端 未结 16 1020
挽巷
挽巷 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:22

    In java, everything is represented as an object except a few cases. When you are about to instantiate the class (A blueprint), you must know the exact size of the class member variables, member methods, and the constructors. Since some/all of the methods are abstract, and JVM doesn't know the size. Hence allocating memory is useless.

    But We can implement something to overcome this problem If we take the memory allocation part away from the JVM and assign this ownership to the USER.

提交回复
热议问题