using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication7 { class Pconstructor { //Private fields of class int A, B; //default Constructor public Pconstructor() { A = 10; B = 20; } //Paremetrized Constructor public Pconstructor(int X, int Y) { A = X; B = Y; } //Method to print public void Print() { Console.WriteLine("A = {0}\tB = {1}", A, B); } } class MainClass { static void Main() { Pconstructor T1 = new Pconstructor(); //Default Constructor is called Pconstructor T2 = new Pconstructor(80, 40); //Parameterized Constructor is called T1.Print(); T2.Print(); Console.Read(); } } }
Output :
Tags:
csharp.net