OLAP

We are sharing our fourth question of the series in the form of comic, Please help our interview aspirant in the comic by sharing your answers through comments Facebook or Google plus or twitter[@CodeSpreadBlog].

Could you please tell me different ways to achieve mutiple inheritance in c#? with an example.

Multiple Inheritence @Pixton

C# doesn't support multiple inheritance because of dimaond problem,but we can still achieve it using interfaces. Please refer the example below !!

MI-Answer @Pixton


class A
{
public void MethodA()
{
Console.WriteLine("Class A called");
}
}

interface IB
{
void MethodB();
}

class Child : A, IB
{

public void MethodB()

{
Console.WriteLine("Interface B implemented in Class Child ");
}
}
class Program
{
static void Main(string[] args)
{
C objC = new C();
objC.MethodA();
objC.MethodB();
Console.Read();
}
}

 

Results:

Results

Results

Author: hershey

A passion for knowledge drives me to do programming, A passion for programming drives me to create something different, A passion for creation drives me to spread the knowledge.

Share This Post On

0 Comments

  1. nice superb explaination

    Post a Reply
  2. thanks for the tutorial
    I am having a problem.
    The feature “Create SQL server database” isn’t available , I can’t select it.
    Can you help, please ?

    Post a Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

More from CodeSpread:

  • Interview Series: DLR Question-Answer UpdatedInterview Series: DLR Question-Answer UpdatedWe are sharing our second question in the form of comic, Please help our guy in the comic by sharing your answers through comments or Facebook or Google plus or twitter. We have received the answe...
  • Interview Question Series: 1st AnswerInterview Question Series: 1st AnswerWe shared our first comic on interview question two days back and today we are sharing our answer for the question. This is one of our attempt to learn the basics in a unique way. Interview Ques...
  • Interview Series: 3 More Questions.Interview Series: 3 More Questions.We are sharing few more questions of the series in the form of comic, Please help our interview aspirant in the comic by sharing your answers through comments, Facebook or Google plus or twitter[@C...
  • Interview Series: Polymorphism Question- Answer UpdatedInterview Series: Polymorphism Question- Answer UpdatedWe are sharing our third question of the series in the form of comic, Please help our kid in the comic by sharing your answers through comments or Facebook  or Google plus or twitter[@CodeSpreadBlo...
  • Interview Question SeriesInterview Question SeriesWe have shared our experiences with our readers from quite sometime. Today, when one of our readers asked us to write some interview questions then we realized that we should take an initiative and...
  • Why Multiple Inheritance is discouraged?Why Multiple Inheritance is discouraged?Hi Guys, This is Sathish Again,Today we will discuss why most of the higher languages eliminates Multiple Inheritance? Most of you guys already know that multiple inheritance is not available for...
  • Time Out: Not a Technical postTime Out: Not a Technical postTaking my time-out from technical world for once and sharing a regular joke in the form of  this comic with you. There is no harm in showing funny side also sometimes. wat say!!
  • IQueryable: Performance boost over remote Data AccessIQueryable: Performance boost over remote Data AccessIf we also follow the inheritance principle like OOPS programming, we need to extend our previous discussion “IEnumerable: Power behind Collections”. So this will lead us to write something about I...