How to Inherit in C# with Classes
https://www.saqibsomal.com/c-sharp/how-to-inherit-in-c-with-classes/16
How to Inherit in C# with Classes
Inheritance, in C Sharp, is the ability to create a class that inherits attributes and behaviors from an existing class. The newly created class is the derived or child class and the existing class is the base (or parent) class. Inheritance is one of the key features of object-oriented programming.
Example 1
using System; class Animal public Animal() Console.WriteLine(“Animal constructor”); public void Greet() Console.WriteLine(“Animal says Hello”); public void Talk() Console.WriteLine(“Animal talk”); public virtual void Sing() Console.WriteLine(“Animal song”);
class Dog : Animal public Dog() Console.WriteLine(“Dog constructor”); public new void Talk() Console.WriteLine(“Dog talk”); public override void Sing() Console.WriteLine(“Dog song”);
class test static void Main() Animal a1 = new Animal(); a1.Talk(); a1.Sing(); a1.Greet();
Example 2
using System; class Software public Software() m_x = 100; public Software(int y) m_x = y; protected int m_x;
class MicrosoftSoftware : Software public MicrosoftSoftware() Console.WriteLine(m_x);
class test static void Main() MicrosoftSoftware m1 = new MicrosoftSoftware();
Example 3
using System;
class Color public virtual void Fill() Console.WriteLine(“Fill me up with color”); public void Fill(string s) Console.WriteLine(“Fill me up with 0”,s); class Green : Color public override void Fill() Console.WriteLine(“Fill me up with green”);
class colortry
static void Main() Green g1 = new Green(); g1.Fill(); g1.Fill(“violet”);










