CSharp - Testing the call sequence of constructors

Description

Testing the call sequence of constructors

Demo

using System;

class Parent/*from   w  ww  .ja v a 2s .com*/
{
    public Parent()
    {
        Console.WriteLine("At present: I am in Parent Constructor");
    }
}
class Child : Parent
{
    public Child()

    {
        Console.WriteLine("At present: I am in Child Constructor");
    }
}
class GrandChild : Child
{
    public GrandChild()
    {
        Console.WriteLine("At present: I am in GrandChild Constructor");
        }
}

class Program
{
    static void Main(string[] args)
    {

        GrandChild grandChild = new GrandChild();
        Console.ReadKey();
    }
}

Result

Related Topic