Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

multiple inheritance problem in c#?

dear friends,

i have declared 3 interfaces, Kitchen{ IsCooking();} Bedroom{ bool isSleeping(bool);}, Garden{ bool isCuttingGrass(bool);}

i try to inherit and implement using a new classes

public class Myhome: Bedroom, Kitchen, Garden

{

//none of my previously declared member in each interfaces appears.

}

so, what is the problem

thanks

2 Answers

Relevance
  • Anonymous
    10 years ago
    Favorite Answer

    multiple inheritance is not possible in c# in this way

    "public class Myhome: Bedroom, Kitchen, Garden"

    but yes you can do like this

    public class Garden

    {

    //class code

    }

    -----------------------------------------------------

    public class Bedroom: Garden{

    //class code

    }

    -----------------------------------------------------

    public class Myhome : Bedroom

    {

    //class code

    }

    you have to inherits class one by one.

  • wetzel
    Lv 4
    4 years ago

    There are particularly some clarification why it does not. 2 reasons appropriate on the element of the precise of the checklist are 'human beings do no longer are extensive wide awake of it' and 'computers hit upon it complicated to delight in'. human beings have great undertaking information single inheritance. Many commercial companies have coding standards that actively attempt to suppress human beings from transforming into deep inheritance hierarchies. extra in many situations than now no longer composition may well be used to create an comparable result as inheritance without being so stressful to delight in by technique of utilising the guy who has to maintain the code 3 years later. Why human beings have problems information inheritance, so do computers. If a sort X inherits from P and Q and the two P and Q inherit from B, what happens as quickly as you attempt to reliable X to B? If B has digital persons, the two P and Q would have overridden them in distinctive recommendations, so extremely possibly there are 2 Bs, which one do you supply? aside from if the type hierarchy is particularly deep how do you seek for it effectively? So Java and C# circulate for simplicity, you have one and positively one base style. searching for the backside style is a linear seek for from precise to backside, simple, speedy and smart. yet diverse inheritance is clever, it extremely is a danger that an comparable style would p.c.. to indicate itself in yet in any different case to distinctive customers. it extremely is comprehensive by technique of utilising utilising interfaces. An interface is equivalent to a base style, yet includes no information and no strategies. as quickly as you enforce an interface you would be able to offer each and all the persons it needs, it particularly is difficulty-loose to delight in. on the comparable time via fact the laptop casts to the interface all it needs to do is initiate up from the form merchandise and seek for upwards via the backside training searching for one that implements the interface. Interfaces do 95% of the paintings diverse inheritance for 10% of the recommendations area and 15% of the CPU area. The 5% that interfaces won't be in a position of do this diverse inheritance can may well be basically performed by technique of utilising composition.

Still have questions? Get your answers by asking now.