Multilevel inheritance C sharp program example

Multilevel inheritance C# program example- In Multilevel inheritance, a class is derived from another class which is also derived from some another class … For example class C : class B and class B : class A then this type of inheritance is known as multilevel inheritance.

/*
 * Multilevel inheritance java program example
 */
 
/*
 * In this program we basically performing three tier level
 * of inheritance.
 */
 
//Class GrandFather is the base class or parent class
public class GrandFather 
{
 
	public void oldage()
        {
 
		Console.WriteLine("we are in grandpa class");
	}
}
 
// Father class is the child class of class Grandfather
class Father : GrandFather 
{
 
	public void Age() 
        {
 
		Console.WriteLine("we are in father class");
	}
}
 
// class Baby is the child class of class Father
class Baby : Father {
 
	public void newage() 
        {
		Console.WriteLine("we are in baby class");
	}
 
	public void play() 
        {
		Console.WriteLine("Baby is Playing");
	}
}
 
// client class with all the method calls
class TestMultiLevelInheritence 
{
 
	// Display method under which different methods are called
	// through the reference of the child class Baby
	public static void Display() 
        {
 
		// creating object of the class Baby
		Baby b = new Baby();
 
		b.oldage();
		b.Age();
		b.newage();
		b.play();
	}
 
	// main method with Display Method call...
	public static void Main(String[] args)
       {
		Console.WriteLine("Information:");
		Display();
 
	}
 
}


Output:

Information:
we are in grandpa class
we are in father class
we are in baby class
Baby is Playing

Related Posts