Solved

Multiple Inheritance

Posted on 2003-12-08
5
691 Views
Last Modified: 2010-04-16
Can A Form/Control ..anything, inherit more than one thing?
0
Comment
Question by:derekthornton
  • 3
5 Comments
 
LVL 18

Expert Comment

by:testn
ID: 9896907
Nope, .NET doesn't have multiple inheritance feature as of .NET 1.1
0
 
LVL 7

Expert Comment

by:TransBind
ID: 9896961
C# supports single class inheritance only.  Therefore, you can specify only one base class to inherit from.  However, it does allow multiple interface inheritance.
0
 
LVL 7

Accepted Solution

by:
TransBind earned 500 total points
ID: 9897020
An interface looks like a class, but has no implementation.  The only thing it contains are definitions of events, indexers, methods and/or properties.  The reason interfaces only provide definitions is because they are inherited by classes and structs, which must provide an implementation for each interface member defined.


public class DumpTruck: IEngine, IBody
{

void IEngine.Test()
{
Console.WriteLine("This is the Engine TEst");
}
void IBody.Test()
{
Console.WriteLine("This is the Body TEst");
}
}
0
 
LVL 7

Assisted Solution

by:TransBind
TransBind earned 500 total points
ID: 9897037
Another example for u

1:  //  Multi.cs -
 2:  //-----------------------------------------------------------
 3:
 4:  using System;
 5:
 6:  public interface IShape
 7: {
 8:     // Cut out other methods to simplify example.
 9:     double Area();
10:     int Sides { get; }
11:  }
12:
13:  public interface IShapeDisplay
14:  {
15:     void Display();
16:  }
17:
18:  public class Square : IShape, IShapeDisplay
19:  {
20:     private int InSides;
21:     public  int SideLength;
22:
23:     public int Sides
24:     {
25:        get { return InSides; }
26:     }
27:
28:     public double Area()
29:     {
30:        return ((double) (SideLength * SideLength));
31:     }
32:
33:     public double Circumference()
34:     {
35:        return ((double) (Sides * SideLength));
36:     }
37:
38:     public Square()
39:     {
40:        InSides = 4;
41:     }
42:
43:     public void Display()
44:     {
45:        Console.WriteLine("\nDisplaying Square information:");
46:        Console.WriteLine("Side length: {0}", this.SideLength);
47:        Console.WriteLine("Sides: {0}", this.Sides);
48:        Console.WriteLine("Area: {0}", this.Area());
49:     }
50:  }
51:
52:  public class Multi
53:  {
54:     public static void Main()
55:     {
56:        Square mySquare = new Square();
57:        mySquare.SideLength = 7;
58:
59:        mySquare.Display();
60:     }
61:  }

Output
Displaying Square information:
Side length: 7
Sides: 4
Area: 49

0
 
LVL 2

Author Comment

by:derekthornton
ID: 9897120
Er,sorry, didn't see it was the same person both times. I split the points, but I guess that doesn't make a difference, Lol! Thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question