什么是一个抽象类和接口之间的区别? [英] What is the difference between an abstract class and an interface?

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

问题描述

可能重复:结果
接口VS抽象类(一般OO)

我都不能实例化一个抽象类?如果是这样,为什么我不能让我的所有非密封类抽象?

Can I ever instantiate an Abstract class? If so, why would I not make all my non-sealed classes abstract?

如果我不能实例化,然后是从一个接口的区别?抽象类可以有基地级的功能?是否有更多的接口和抽象类相比,有什么区别?

If I can't instantiate it, then what is the difference from an interface? Can the abstract class have "base" class functionality? Is there more to the difference between an interface and an abstract class than that?

推荐答案

您不能实例化一个抽象类。

You can't instantiate an abstract class.

一个抽象类和接口之间的区别是一个抽象类可以有方法的默认实现,所以如果你没有在派生类中覆盖它们,抽象基类实现时使用。接口不能有任何实现。

The difference between an abstract class and an interface is that an abstract class can have a default implementation of methods, so if you don't override them in a derived class, the abstract base class implementation is used. Interfaces cannot have any implementation.

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

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