This course will be retired on July 31, 2026. We recommend "Practice Java Objects - Word Guessing Game" for up-to-date content.
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 Java Objects (2016)!
You have completed Java Objects (2016)!
Preview
Let's learn about constructors to require information at object creation time.
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
Now, hard coded meaning it's
permanently set to a value.
0:00
So that's not really what we want, right?
0:01
We want to allow that character
to be configurable, but
0:03
really only at creation time.
0:07
We'd like to allow consumers of our code
to create whatever character type of
0:09
Pez dispenser they want when
they create a new one, but
0:13
we don't want it to change
after it's created.
0:17
The common solution to this problem is to
create what is known as a constructor.
0:20
A constructor is a method that will
run when you instantiate the class.
0:24
Again instantiation happens when you
create the new instance of the class
0:29
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