Write a code snippet to show non-parameterized constructor?

Tripati_tutu
Posted by Tripati_tutu under C# category on | Points: 40 | Views : 2350
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NonParameterizedConst
{
class Program
{
int x;
public Program() // non-parameterized constructor
{
x = 10;
}
static void Main(string[] args)
{
Program obj1 = new Program();
Console.WriteLine(obj1.x);
Program obj2 = new Program();
Console.WriteLine(obj2.x);
Console.ReadKey();
}
}
}

In the above example the constructor will be invoked by the CLR for two times since two objects are created. In this the constructor will assign same value for all the objects.

Comments or Responses

Login to post response