为什么抽象允许修改?为什么界面不允许修改 [英] Why abstract allow the modification ? why interface does not allow the modification

查看:83
本文介绍了为什么抽象允许修改?为什么界面不允许修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抽象类和接口类似,但抽象类修改是



possible.interface修改实际上不可能发生什么时候



在抽象类或界面中添加方法



我尝试过的方法:



abstract classes and interface are similar but abstract classes modification is

possible.interface modification is not possible actually what happen whenever

Add method in abstract classes or interface

What I have tried:

.

推荐答案

你在哪里知道抽象类可以修改但接口不能?

不同之处在于接口根本不能定义代码,它们只是设置了调用必须实现的签名才能添加接口。接口不是类,它们是成员合同,当遵循时允许实现类成为接口俱乐部的成员。

抽象类可以定义代码,可以在派生类。抽象类是一个完整的类,条件是抽象类无法实例化:您不能直接在抽象类上新建 new 关键字。



差异允许一个类派生自 - 例如 - Control,但也实现了一个接口,如IEnumerable,允许它在 foreach中使用循环。



抽象类和接口不一样,如果不改变抽象类或接口的源代码,也不能修改它们。
Where did you get the idea that abstract classes could be modified but interfaces can't?
The difference is that interfaces can define no code at all, they just set out the signatures that a calls must implement in order to add the interface. Interfaces are not classes, they are a "membership contract" which when followed allows the immplementing class to become a "member of the interface's club".
An abstract class can define code, which can be overridden in derived classes. An abstract class is a full class, with the proviso that an abstract class cannot be instantiated: you cannot new the new keyword directly on an abstract class.

The difference allows a class to be derived from - for example - Control, but also implement an interface such as IEnumerable which permits it to be used in a foreach loop.

Abstract classes and interfaces are not the same, and neither can be "modified" without changing the source code for the abstract class or interface.


检查: oop - Interface vs Abstract类(一般OO) - 堆栈溢出 [ ^ ]


接口不是类,请参见此处的解释:抽象类与界面 [ ^ ]
An interface is not a class, see explanation here: Abstract Class versus Interface[^]


这篇关于为什么抽象允许修改?为什么界面不允许修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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