需要抽象类和接口? [英] Need for Abstract Class as well as Interface?

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

问题描述

接口是100%抽象类,因此我们可以使用接口进行高效编程。是否存在抽象类优于接口的情况?

An interface is a 100% abstract class, so we can use an interface for efficient programming. Is there any situation where an abstract class is better than an interface?

推荐答案

当您打算创建一个抽象类时,会使用抽象类具体类,
但是要确保所有子类
中存在一些公共状态或某些操作可能的公共实现

Abstract classes are used when you do intend to create a concrete class, but want to make sure that there is some common state in all the subclasses or a possible common implementation for some operations.

接口也不能包含。

这篇关于需要抽象类和接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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