Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Objects Object-Oriented Programming Practice Writing Classes

Liam Andersson
Liam Andersson
1,396 Points

Constructor X,Y

Jeremy wrote X = x; and Y = y; why didn't he define X and Y as an integer or double? X, Y and Z are always numbers right?

And what exactly is a constructor? Im a bit confused over the constructor bit ;/

2 Answers

Steven Parker
Steven Parker
231,248 Points

Since C# is case-sensitive, then "X" (capital) and "x" (lower case) are two different variable names. Same with "Y" and "y". And he did define "X" and "Y" both as "int" types, a few lines above where the constructor starts.

"X", "Y", and "Z" are just variable names, nothing special and not required to be any specific type.

And a constructor is a special method that runs automatically when you create an instance of a class. It will typically establish initial states such as setting up variables as is being done here.

Liam Andersson
Liam Andersson
1,396 Points

He did? Then I missed it.. Well Thanks

Your comments are so helpful! Thanks a lot, man!

He define both as "int" types in this line of code:

public Point(int x, int y)