C# Example for MultiLevel Inheritance

CsharpServer Side ProgrammingProgramming

Multilevel Inheritance occurs when a derived class is formed from another derived class.

Grandfather, father, and son are the perfect example to represent Multilevel Inheritance in C# −

Example

The following is an example stating the usage of multilevel inheritance in C#.

Live Demo

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo {
   class Son : Father {
      public void DisplayTwo() {
         Console.WriteLine("Son.. ");
      }
      static void Main(string[] args) {
         Son s = new Son();
         s.Display();
         s.DisplayOne();
         s.DisplayTwo();
         Console.Read();
      }
   }
   class Grandfather {
      public void Display() {
         Console.WriteLine("Grandfather...");
      }
   }
   class Father : Grandfather {
      public void DisplayOne() {
         Console.WriteLine("Father...");
      }
   }
}

Output

Grandfather...
Father...
Son.. 
raja
Published on 24-Jul-2018 11:53:43
Advertisements