抽象和接口之间的区别

问题描述:

抽象与接口之间的区别





1)抽象类与界面



2)抽象类和接口之间的区别 >


3) C# - 摘要之间的区别Asp.Net中的类和接口



4)接口或抽象类?


抽象类和接口之间的关键技术差异是:



1.抽象类可以有常量,成员,方法存根和定义的方法,而接口只能有con sts和方法存根。



2.可以使用任何可见性定义抽象类的方法和成员,而接口的所有方法都必须定义为public。 br />


3.继承抽象类时,具体子类必须定义抽象方法,而抽象类可以从父类扩展另一个抽象类和抽象方法不必定义。



4.同样,扩展另一个接口的接口不负责从父接口实现方法。这是因为接口无法定义任何实现。



5.子类只能扩展单个抽象(或任何其他)类,而接口可以扩展或者class可以实现多个其他接口。



6.子类可以定义具有相同或更少限制的可见性的抽象方法,而实现接口的类必须定义方法具有完全相同的可见性。
The key technical differences between an abstract class and an interface are:

1. Abstract classes can have constants, members, method stubs and defined methods, whereas interfaces can only have consts and methods stubs.

2. Methods and members of an abstract class can be defined with any visibility, whereas all methods of an interface must be defined as public.

3. When inheriting an abstract class, a concrete child class must define the abstract methods, whereas an an abstract class can extend another abstract class and abstract methods from the parent class don't have to be defined.

4. Similarly, an interface extending another interface is not responsible for implementing methods from the parent interface. This is because interfaces cannot define any implementation.

5. A child class can only extend a single abstract (or any other) class, whereas an interface can extend or a class can implement multiple other interfaces.

6. A child class can define abstract methods with the same or less restrictive visibility, whereas a class implementing an interface must define the methods with the exact same visibility.