接口和抽象类有什么区别? [英] What's the difference between an interface and an abstract class?

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

问题描述

何时使用接口而不是抽象类,反之亦然?

可能是最著名的软件开发人员工作面试问题之一.

Probably one of the most famous software developer job interview questions.

你的答案是什么?

我想知道你会如何在现实生活中回答这个问题.请尝试像在真实的工作面试中一样制定您的答案(完整,但不要太长,当然不要发布链接).

I'm trying to find out how you would answer this in a real-life situation. Please try to formulate your answer as you would on a real job interview (be complete, but don't be too long, post no links of course).

推荐答案

接口只描述其方法的实际签名等.任何实现该接口的类都必须提供显式实现.

An interface only describes the actual signature of its methods etc. Any class implementing that interface must then provide an explicit implementation.

抽象类可以包含其方法等的部分实现.

An abstract class can contain a partial implementation of its methods etc.

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

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