B.Sc.IT (Semester: V)
ASP.NET With C# [Practical Question]
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();
}
}
}

Write a program to show the example of hybrid inheritance.

  • 1.
    B.Sc.IT (Semester: V) ASP.NETWith C# [Practical Question] 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 {
  • 2.
    int c; public C(intx, 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(); } } }