C# Method Constructor Question from Quiz

Hi, I got this wrong on the quiz. I am confused why the class would run, if I am only creating an ‘object’
Method%20Quiz

It would make sense if I called it like, Player();

Constructors run when creating an instance of the class (ignore static constructors). This class has 2 constructors: one that takes in a player name and one that takes in nothing. The one that takes in nothing will call the constructor that takes in a player name, passing in the name “n/a”. This is called constructor chaining.

public Player() : this("n/a")

The this(“n/a”) part is where it is calling the other constructor.

So the first constructor is always called no matter.

1 Like