How do you create multiple inheritance in C#?
Answers were Sorted based on User's Feedback
Answer / shafi syed
C# does'nt support multiple inheritance. In that situation
we use interface
| Is This Answer Correct ? | 108 Yes | 8 No |
Answer / jiten
if u want to crate multile inheritance in C#
u can use intface
| Is This Answer Correct ? | 98 Yes | 10 No |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestApp
{
class MultipleInheritance : first, Isecond
{
Isecond objsecond = new second();
#region Isecond Members
public void secondfunction()
{
objsecond.secondfunction();
}
#endregion
}
class first
{
public first()
{
}
public void firstfunction()
{
Console.WriteLine("First funciton called");
}
}
interface Isecond
{
void secondfunction();
}
class second : Isecond
{
public second()
{
}
public void secondfunction()
{
Console.WriteLine("Second function called");
}
}
class Program
{
static void Main(string[] args)
{
//multiple inheritance
MultipleInheritance obj = new MultipleInheritance();
obj.firstfunction();
obj.secondfunction();
Console.ReadLine();
}
}
}
| Is This Answer Correct ? | 47 Yes | 19 No |
Answer / pavankumar
C# doesn't support Multiple Inheritance,,,SO to over come this problem Interface came into picture.Interface is not a class,but it is a parent to base class.
Interface Forest
{
void Greet();
}
class Animal: Forest
{
public void Greet()
{
Console.WriteLine("Animal says Hello");
}
public void Sing()
{
Console.WriteLine("Animal Sings");
}
}
class Program : Animal,Forest
{
static void Main(string[] args)
{
Program obj = New Program();
obj.Greet();
obj.Sing();
Console.ReadLine();
}
}
| Is This Answer Correct ? | 5 Yes | 3 No |
Answer / frank
using System;
interface Interdemo
{
void Show();
}
class Interimp:Interdemo
{
public void Show()
{
Console.WriteLine("Show() method Implemented");
}
public static void Main(string[] args)
{
Interimp inter = new Interimp();
inter.Show();
}
}
| Is This Answer Correct ? | 36 Yes | 36 No |
What is action c#?
Can c# inherit multiple classes?
What does the This window show in the debugger?
What is the role of the datareader class in ado.net connections?
What is the c# equivalent of c++ catch (…), which was a catch-all statement for any possible exception? Does c# support try-catch-finally blocks?
What is the difference between list and arraylist in c#?
Do extension methods have to be static?
What is session variable in c#?
What are the different types of delegation?
How can you access a private method of a class?
hi, is compulsory .net knowledge need for biztalk server training. if need, how far?.tell me some info abt real time instructors in hyd or other?
Define a jagged array in c#?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)