确切使用抽象类的 [英] Exact use of Abstract class

查看:86
本文介绍了确切使用抽象类的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是抽象类的确切用途?是不是可以做到同样的事情在一个普通的类,因为它是一个抽象类?

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?

推荐答案

使用一个抽象类,提供一些具体的实现,但不会允许实例化。您可以随时实例化一个普通类,它没有任何意义,如果它不能单独存在。同时,如果有一个具体的实现,在所有执行类相同的接口可能是不够的。抽象类是刚好够用。

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.


  • 接口:合同而已,没有实现,没有实例

  • 抽象类:合同,有的实现,没有实例

  • 类:合同,执行,实例化

这篇关于确切使用抽象类的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆