Saturday, 27 February 2016

C#.NET ---- MULTI LEVEL INHERITANCE

MULTI LEVEL INHERITANCE

Multilevel inheritance is one type of inheritance which deriving a child class from already derived parent class that is acquiring the properties of  a class which acquires some properties from another class.

Suppose class B acquired one methods form Class A, and class C acquired from class B then all properties of class A and class B of both can access by class C.

for example, a person B acquires some properties from his father A, and person is C is son of person B who can acquires his father B properties and his fathers father A properties both.



Ex :

class father    
{
  public void fProperty()
{
  Console.WriteLine("I have one big house ");
 }
}
class Person : father    // this is first level of inheritance
{
  public void pProperty()
 {
  Console.WriteLine("I have10kg gold ");
 }
}
class son : Person     // this is second level of inheritance
{
  public void sProperty()
  {
    Console.WriteLine("I have a car ");


}

}
class Program
{
 static void Main()
{
  son s = new son()
   s.fProperty();  // his father property
   s.pProperty();  // person property
   s.sProperty();   // his son property
   Console.ReadKey();
}
}

Output :
I have one house
I have 10kg gold
I have a car


---------------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment