abstact类和接口(带有示例)之间有什么区别。 [英] What is the difference between an abstact class and an interface (with examples).

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

问题描述

我想要明确解释这种差异以及它可以在项目中使用的位置。

I want a clear explanation about that difference and where it can be used in projects.

推荐答案

区别很简单:

接口不是类,不能实例化。它不能包含任何具体代码,只能包含抽象定义。您可以继承一个接口以及一个基类,只要您完成合同并实现它所需的方法和属性。



抽象类是不同的:你仍然无法实例化它 - 这意味着你不能说

The difference is simple:
An interface is not a class, and cannot be instantiated. It cannot contain any concrete code, only abstract definitions. You can inherit an Interface as well as a single base class, provided you complete the "contract" and implement the methods and properties it requires.

An abstract class is different: you still can't instantiate it - which means you can't say
MyAbstractBase mab = new MyAbstractBase();

但如果从派生类派生,则无法同时从任何其他类派生。抽象类可以包含具体代码,如果它没有在派生类中重写,将使用它。



这是一个相当复杂的主题,你应该真的从C#教程开始了解详细信息: http://csharp.net-tutorials.com/classes/interfaces/ [ ^ ]是一个很好的基础。

but if you derive from an abstract class you cannot derive from any other class at the same time. An abstract class can contain concrete code, which will be used if it isn't overridden in the derived class.

This is a fairly complicated subject, and you should really start with a C# tutorial for the details: http://csharp.net-tutorials.com/classes/interfaces/[^] is a good basis.


你可以在这里参考这个网站,每个学期都清楚地解释了退房



抽象类和接口之间的差异 [ ^ ]
you can refer to this site here each and every term is clearly explained check-out

Difference between abstract classes and interfaces [^]


尝试在谷歌找... ..



这里是一些链接给你.. :)



抽象类与接口 [ ^ ]



C# - Asp.Net中抽象类和接口之间的差异 [ ^ ]



抽象类和接口之间的差异 [ ^ ]



抽象类和界面之间的差异: [ ^ ]



抽象类与接口 [ ^ ]
try to find in google.. :)

here is some links for you.. :)

Abstract Class versus Interface[^]

C# - Difference between Abstract class and Interface in Asp.Net[^]

Difference between abstract class and interface[^]

DIFFERENCE BETWEEN AN ABSTRACT CLASS AND AN INTERFACE:[^]

Abstract Class vs Interface[^]


这篇关于abstact类和接口(带有示例)之间有什么区别。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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