Write a program to show the example of Hybrid Inheritance.


Write a program to show the example of Hybrid Inheritance.
Write a program to show the example of Hybrid Inheritance.

DOWNLOAD (PDF): @GitHub | @SlideShare

QUESTION:
Write a program to show the example of Hybrid Inheritance.

SOLUTION:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class A
{
public int a;
public A(int p)
{
a = p;
}
public void showA()
{
Console.WriteLine(“A=” + a);
}
}
class B : A
{
int b;
public B(int z, int y)
: base(z)
{
b = y;
}
public void showB()
{
Console.WriteLine(“B=” + b);
}
}
class C : A
{
int c;
public C(int x, int m)
: base(x)
{
c = m;
}
public void showC()
{
Console.WriteLine(“C=” + c);
}
}
class D : B
{
int d;
public D(int x, int y, int z)
: base(x, y)
{
d = z;
}
public void showD()
{
Console.WriteLine(“D=” + d);
}
}
class Program
{
static void Main(string[] args)
{
C c1 = new C(5, 9);
D d1 = new D(4, 2, 3);
c1.showA();
c1.showC();
d1.showA();
d1.showB();
d1.showD();
Console.ReadKey();
}
}
}


0 Comments