Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you identify a default constructor?

Tags:

c#

oop

I am new to OOP.

I have read that "the constructor which takes no arguments is called the default constructor".

Is the below constructor a default constructor?

Class A
{
  int a;
  string b;

  public A()
  {
    a=10;
    b="Test";
  }
}
like image 403
Alvin Avatar asked Feb 07 '26 09:02

Alvin


1 Answers

Yes, it is, since it doesn't have any parameters/arguments.

An example of a non-default constructor would be:

public A(int a)
{
   this.a = a;
}
like image 90
Zach Johnson Avatar answered Feb 09 '26 07:02

Zach Johnson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!