Embed presentation
Download to read offline
![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
{](https://image.slidesharecdn.com/writeaprogramtoshowtheexampleofhybridinheritance-180911185117/85/Write-a-program-to-show-the-example-of-hybrid-inheritance-1-320.jpg)
![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();
}
}
}](https://image.slidesharecdn.com/writeaprogramtoshowtheexampleofhybridinheritance-180911185117/85/Write-a-program-to-show-the-example-of-hybrid-inheritance-2-320.jpg)

This document provides an example of hybrid inheritance in C# by defining four classes - A, B, C, and D - where B inherits from A, C inherits from A, and D inherits from B. It demonstrates hybrid inheritance by creating instances of classes C and D, and calling methods on each to output their property values.
![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
{](https://image.slidesharecdn.com/writeaprogramtoshowtheexampleofhybridinheritance-180911185117/85/Write-a-program-to-show-the-example-of-hybrid-inheritance-1-320.jpg)
![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();
}
}
}](https://image.slidesharecdn.com/writeaprogramtoshowtheexampleofhybridinheritance-180911185117/85/Write-a-program-to-show-the-example-of-hybrid-inheritance-2-320.jpg)