0
what is Differences between abstract class and interface ? please answer anyone.
4 Antworten
+ 2
tl;dr interface is not a class, abstract class is.
First of all interface is not a class it is how you can communicate with something. For example human interface is language.
Every class contains interface, that is the way you can interact with that class.
Even if some class doesn't inherit from any interface in your code implicitly it still has interface. That is everything you can access. (ex. class.Member)
Abstract class just means it is too broad to have some specific implementation. But it will have an interface like any other class.
And when we define interface we define a contract or protocol in other words by which all classes that share that interface will be able to communicate with the world.
It is more about semantics but if you get it right your code will be more flexible, easy to change, reuse and adapt.
*Interfaces doesn't break single inheritance because they are not classes.
0
1.An Abstract class doesn't provide full abstraction but an interface does provide full abstraction; i.e. both a declaration and a definition is given in an abstract class but not so in an interface.
2.Using Abstract we can not achieve multiple inheritance but using an Interface we can achieve multiple inheritance.
3.We can not declare a member field in an Interface.
4.We can not use any access modifier i.e. public , private , protected , internal etc. because within an interface by default everything is public.
5.An Interface member cannot be defined using the keyword static, virtual, abstract or sealed.
0
@Rezza You are welcome to copy/paste from an internet source but you should add a source citation. Manish Sharma wrote the text you copied from the source I'd post below. Please be fair ;)