Solved

Multiple Inheritance

Posted on 2003-12-08
5
689 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now