Why can't we create an instance of an abstract class?

前端 未结 7 2283
再見小時候
再見小時候 2021-01-04 13:29

I found in many places that :

  • An Abstract Class is a class which is supposed to be used as a base class.
  • An Abstract Class is a class which has atleas
7条回答
  •  日久生厌
    2021-01-04 13:52

    An abstract class represents something that isn't specific enough to be instantiated. For instance, what if someone asked you to create a vehicle? You'd have to ask, "what kind of vehicle?" You wouldn't know whether to create a car, a sled, or a space shuttle. There's no such object as a "vehicle". Yet "vehicle" is a useful abstraction that can be used to group objects, indicating common behaviors among them. That's what abstract classes are for.

提交回复
热议问题