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 |
How to exclude a property from xml serialization?
What is the value which is accepted by all data types ?
Define Virtual folder?
What is the use of table aliases?
What is reflection c#?
What is raise event and what is its use?
What is the difference between dataset and datatable in c#?
hi i m bhawna ,a student of mca want to know about what type of technical question has been asked in an interview of mnc's like HCL,TCS,WIPRO
What is marshalling and what are different kinds of marshalling?
What is a helper method in c#?
Is there an equivalent to the instanceof operator in visual j++?
What is xml serialization in c#?