Constructor and Destructor

Ranjeet_8
Posted by Ranjeet_8 under C# category on | Points: 40 | Views : 1753


class Program
{
static void Main(string[] args)
{
Three t = new Three();
Console.ReadLine();

}
}



class One
{
//Constructor
public One()
{
Console.WriteLine("First Constructor Called");
}

//Destructor
~One()
{
Console.WriteLine("First destructor is called.");
Console.ReadLine();
}
}








class Two : One
{
//Constructor
public Two()
{
Console.WriteLine("Second Constructor Called");

}
//Destructor
~Two()
{
Console.WriteLine("Second destructor is called.");

}
}

class Three : Two
{
//Constructor
public Three()
{
Console.WriteLine("Third Constructor Called");
}
//Destructor
~Three()
{
Console.WriteLine("Third destructor is called.");

}
}



/*The result of this Program will be:-
First Constructor Called
Second Constructor Called
Third Constructor Called

Third destructor is called.
Second destructor is called.
First destructor is called.
*/

Comments or Responses

Login to post response