MULTIPLE CLASS INHERITANCE PROBLEM IN C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleApplication4;
namespace ConsoleApplication4
{
/// <summary>
///
/// PROBELMS WITH MULTIPLE CLASS INHERITANCE
/// </summary>
class A
{
public virtual void print()
{
Console.WriteLine("class A implemented");
}
}
class B : A
{
public override void print()
{
Console.WriteLine("Class B overriding print() method");
}
}
class C : A
{
public override void print()
{
Console.WriteLine("Class C overriding print() method");
}
}
class D : B, C
{
}
class Program
{
public static void Main()
{
D d = new D();
d.print(); // AMBIGUITY HERE, WHICH METHOD WILL IT EXECUTE, SO A DIAMOND PROBLEM.
}
}
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.