"Python Basics (2015)" was retired on June 22, 2018. You are now viewing the recommended replacement.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed C# Objects!
You have completed C# Objects!
Preview
We can set the values of an object's fields to an initial value when it's created.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
We can make sure that both of these fields
are filled out when the object is created
0:00
by providing a special kind of
method called a constructor method.
0:00
They're called constructors
because they're used to construct
0:04
new instances of a class.
0:08
Let me show you what that looks like here.
0:11
Constructor methods are named
the same as the class they're in.
0:13
The constructor is called
when the object is created.
0:20
If we add parameters to the constructor
method, then the user of this class
0:23
must provide those parameters in order for
the object to be constructed.
0:28
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up