Default constructor in C#

Posted on Updated on

Image result for Default constructor in C#Default constructor in C#

Whenever a constructor is not defined in a class, it is known as default constructor. Default constructor is basically without parameters. If no constructors are defined in a class, default constructor calls the parameter-less default constructor of the direct base class. If the direct base class does not have an accessible default constructor, the compiler throws error. By default the default constructors are public but if the class is abstract then the accessibility of the default constructor is protected.


public A() : base() {…….}


protected A() : base() {………..}

[ in which ‘A’ is the class name ]

Example 1

class Message{

object sender;

string text;


a default constructor is provided because the class contains no instance constructor declarations. Thus, the example is precisely equivalent to

class Message


object sender;

string text;

public Message(): base() {}


Example 2

public class clsAddition{

publicintMycode = 0;


Mycode = 9;



class Program{

static void Main(string[] args){

clsAdditionobj = new clsAddition();

Consolw.WriteLine(“Code value is : {0}”,obj.Mycode);




For more details and queries please feel free to email, visit or call us. Wishing you the very best for all your future endeavors.
Helpline: 9814666333, 8699444666

Please fill the form and we shall contact you soon.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s