Exact use of Abstract class

后端 未结 4 1562
独厮守ぢ
独厮守ぢ 2020-12-05 11:06

What is the exact use of an Abstract class? Is not possible to do the same things in an ordinary class as it is an an abstract class?

4条回答
  •  半阙折子戏
    2020-12-05 11:34

    An abstract class is used when you have some base functionality that you want subclasses to inherit, but it wouldn't make sense to instantiate the base class. For example, if you had something like a Shape base class, you could have some built in implementation that could be used by subclasses as well as interface methods that you want the subclasses to implement. However, it probably wouldn't make sense to create a Shape object. An abstract class gives you this functionality. Another great example of abstract class uses is the abstract factory pattern.

提交回复
热议问题