抽象类的具体使用 [英] Exact use of Abstract class

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

问题描述

抽象类的确切用途是什么?不可能在普通类中做与抽象类相同的事情吗?

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天全站免登陆