CSharp - Testing the call sequence of constructors

Description

Testing the call sequence of constructors

Demo

using System;

class Parent//from w ww  .ja  v  a2s. c  o  m
{
    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