接口和抽象类有什么区别?

接口和抽象类有什么区别?

问题描述:

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

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

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.