Click here to Skip to main content
15,896,456 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Why C# does not support Multiple Inheritance?? Explain with example.
Posted
Comments
Vishal Pand3y 3-Dec-13 6:41am    
do your Home work yourself

C#
public class Parent1
{
    public Parent1()
    {

    }

    public void SayHello()
    {

    }
    public void SayHi()
    {

    }

}

public class Parent2
{
    public Parent2()
    {

    }

    public void SayHello()
    {

    }
    public void SayHi()
    {

    }

}
public class Child : Parent1,Parent2-- Its not possible just for understanding
{
    public void SayHi123()
    {

    }
}
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Child objChild = new Child();
        objChild.SayHello();
        objChild.SayHi();
    }
}

In the above scenario when you call the SayHello or SayHi methods by creating instance of chhild class... that time there is ambiguity from which parent mmethod should get called (Parent1 or Parent2) so they are not allowing to inherit multiple classes... but we can achive the same by multilevel or by interface .
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900