4
Answers

Pure Abstract class vs interface

Photo of manoj singh

manoj singh

7y
245
1
One interviewer asked me about Why c# does not support multiple inheritance Then i Explain the ambiguity thing happens in multiple inheritance. Then he say pure abstract class looks like interface then why we can not inherit more then one pure abstract class ( in concept part its look like same to me also so I confused about need a explaination why Multiple inheritence not supported in c#)

Answers (4)

3
Photo of Manav Pandya
NA 7.1k 24.1k 7y
Hello
 
Ya that not possible because of "diamond" problem
 
For reference go through following link :
 
https://en.wikipedia.org/wiki/Multiple_inheritance#The_diamond_problem
 
Thanks 
Accepted
1
Photo of manoj singh
NA 53 475 7y
Thanks Manav for Diamond Problem Link 
 
After Reading Diamond Problem now i have idea why c# not support multiple inheritance but there are Phrase like - ( "c# allow multiple-inheritance of interfaces. Interfaces are like abstract base classes that specify method signatures without implementing any behavior. Nevertheless, even when several interfaces declare the same method signature, as soon as that method is implemented (defined) anywhere in the inheritance chain, it overrides any implementation of that method in the chain above it. Hence, at any given level in the inheritance chain, there can be at most one implementation of any method. Thus, single-inheritance method implementation does not exhibit the Diamond Problem even with multiple-inheritance of interfaces." ). Can anyone help me to understand these in simple way(if possible then c# example). 
1
Photo of manoj singh
NA 53 475 7y
my question is more related to why multiple inheritence not supported in c# . We do it by interface in c# 
then Why we cannot extend multiple pure abstract class in c# ( as pure abstract class looks same as interface). Then one more question arises if pure abstract class is same as interface then in which condition interface is better option then pure abtract class
 
1
Photo of Manav Pandya
NA 7.1k 24.1k 7y
Hello
 
For Abstarct VS Interface :
 
https://www.codeproject.com/Articles/11155/Abstract-Class-versus-Interface
 
http://www.c-sharpcorner.com/uploadfile/prasoonk/abstract-class-vs-interface/
 
How to achieve Multiple Inheritance in C# :
 
https://www.codeproject.com/Articles/10072/Simulated-Multiple-Inheritance-Pattern-for-C 
 
http://www.c-sharpcorner.com/blogs/multiple-inheritance-in-c-sharp-using-interfaces1
 
Thanks