Interviews4 answers
Q. Is it possible to achieve a mechanism like multiple inheritance in c# without using interface ?
4 Answers
No
Vineet KumarPosted Jan 12, 2017, 8:53 PM EST
to overcome mulitple inheritance we can use only interface
Keerthi VenkatesanPosted Apr 11, 2016, 5:39 AM EDT
No
Sunil BabuPosted Apr 2, 2016, 3:29 AM EDT
Yes it is possible in c# for more details see below example.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LearningPractice
{
class MultipleInheritance
{
// Listing 1 : FamilyClass
public class FamilyClass
{
public FamilyClass()
{
}
protected void GetFamilyName()
{
}
}
// Listing 2 : GrandClass
public abstract class GrandClass
{
protected int age;
protected string name;
public GrandClass()
{
}
public void GetGrandName()
{
}
protected void GetGrandAge()
{
}
}
// Listing 3 : ParentClass
public class ParentClass:FamilyClass
{
private void GetMotherName()
{
}
// GrandClass
public class ChildClass:GrandClass
{
public ChildClass()
{
}
public void ChildMethod()
{
ParentClass plsClass = new ParentClass();
GetGrandName(); // GrandClass
GetGrandAge(); // GrandClass
plsClass.GetMotherName(); // Parent Class
plsClass.GetFamilyName(); // Family Class
}
}
}
static void Main1(string[] args)
{
}
}
}
prashant bathaniPosted Nov 7, 2015, 3:06 AM EST

