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

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

问题描述

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