Create a object of derive class SE and sort-out what is the execution sequence of a) Constructor? b) Static constructor? c) What will happen when we will call the displayName method of child class? d) Mention three ways to call the parent class method using the object of child class


1    Consider an example of a BASE Class University and derive class SE. Following member types should be in both base and derive class.
 
a)      Constructor
b)      Static constructor
c)      A Method displayName with same signatures
      Create a object of derive class SE and sort-out what is the execution sequence of
a)      Constructor?
b)     Static constructor?
c)      What will happen when we will call  the displayName method of child class?
d)     Mention three ways to call the parent class method using the object of child class

using System;
class Uni
{
    public Uni()    // default constuctor of parent
    {
    Console.WriteLine("\n HEllo i m constuctor of parent class Uni");
    }

     static Uni()            //static consructor of parent
   
    {
        Console.WriteLine("\n HEllo i m static  constuctor of Parent Class SE");
  
    }
     public void displayName()
     {
         Console.WriteLine("\n HEllo I m Method of Parent class");

     }

}
class SE:Uni
{
    public SE()             // default constuctor of child
    {
    Console.WriteLine("\n HEllo i m constuctor of Child class SE");
    }
    static SE()               // static constuctor of child
   
    {
        Console.WriteLine("\n HEllo i m static constuctor of Child class SE");
  
    }
    public new void displayName()
    {
        Console.WriteLine("\n HEllo I m Method of child class");
  
    }



}


    class Program
    {
        static void Main(string[] args)
        {
            SE obj=new SE();
            obj.displayName(); // this will call child class method


            ((Uni)obj).displayName();    // call through type casting using parent class

            Uni obj1 = new SE();             // creating reference variable of parent class
            obj1.displayName();

            Console.ReadKey();
        }
    }




Post a Comment

0 Comments