Exact use of Abstract class

后端 未结 4 1567
独厮守ぢ
独厮守ぢ 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:50

    Use an abstract class to provide some concrete implementation but not allow instantiation. You can always instantiate an ordinary class which doesn't make sense if it can't stand alone. At the same time, an interface might not be enough if there's a concrete implementation that's identical in all implementing classes. An abstract class is just enough.

    • Interface: contract only, no implementation, no instantiation
    • Abstract class: contract, some implementation, no instantiation
    • Class: contract, implementation, instantiation

提交回复
热议问题