Suppose we have an interface with few method declaration & similar methods (declared in interface) are declared as abstract method in a abstract class. Both will serve as same purpose like inherit & compulsorily implement all method in base class. So what is key differences between them w.r.t C#. Commonly asked in interviews.
-
1possible duplicate of [pure abstract class and interface](http://stackoverflow.com/questions/2091893/pure-abstract-class-and-interface) – Maroun Mar 05 '14 at 10:46
-
@MarounMaroun It is not duplicate at any rate, because it is not java question here! And there it was a strict java question. And this question in Java and out of it has absolutely different answers. – Gangnus Mar 05 '14 at 11:01
-
Its w.r.t C#. We can make Abstract class to work same as interface by making methods as abstract so whoever inherits it has to implement that method so whats the difference. It is that they are same ? – Vishal Deshmukh Mar 06 '14 at 05:20
4 Answers
Well, In C#, as far as I know, there is no much difference between an Abstract class with all methods being abstract, and an Interface. Any class inheriting from these (abstract class or interface) must implement the methods declared.
But in case of inheritance from an Interface, you can have multiple Interfaces, but for abstract class, you can only have one.
So, instead of having an abstract class have only abstract methods, declare it as Interface.
But if you want to restrict inheritance between interfaces, declare both of them as abstract class with only abstract methods, so that the consumer can only inherit from either of them.

- 11
- 1
The difference is different in different languages.
In Java you can derive a class from ONE abstract class, but/and from MANY interfaces. In Java 8 interfaces can have default methods, too, and that difference between them and Abstract classes remains almost the sole one.
In SmallTalk there is no use of interfaces at all, because all classes can work as interfaces.
In C++ the difference is not distinct and you can use abstract class or interface at your will. Interface there is a case of abstract class.
Don't forget that interface appeared because of technical problems with having two parent classes. And you are talking about theory. In abstract theory there is no need for interface apart from class and your question loses sense. The same in the really OOP languages, as SmallTalk.

- 24,044
- 16
- 90
- 149
I think this question is related to JAVA or C#. In C++ a abstract class is also called an interface. But let's stick to differences between interface and abstract classes ( in JAVA, let's say):
- both interfaces and abstract classes provide series of methods an properties which have to be extended before they can be used.
- multiple inheritance is only supported through interfaces: you can extend multiple interfaces but can only inherit from one class (applies to abstract classes as well)
- an abstract class can provide implementation for some methods and abstractions of others while an interface only provides abstractions which have to be implemented in the classes which extend them.
Which one is better? it depends on your application. For example some design patterns work well with interfaces other are better suited for abstract classes

- 4,843
- 3
- 27
- 44
There is two main difference in abstract class having all abstract method and interface.
1. Multiple Inheritance. - Your class can inherit as more than one interface.
But this is not possible to inherit multiple class in c# because famous diamond problem.
2. Interface will help you to Dependency Injection Problem.
You can check DI problem here -