C# Example for MultiLevel Inheritance


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.. 

Updated on: 19-Jun-2020

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements