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!
You have completed Java Objects!
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
means it's permanently set to a value.
0:00
So that's not really what we want, right?
0:02
We want to allow the character to be
configurable, but only at creation time.
0:04
We'd like to allow consumers of our code
to create whatever
0:09
character type of Pez dispenser
they want when they create a new one,
0:12
but we don't want it to be changed
after it's created.
0:16
The common solution to this problem is
to create what is known as a constructor.
0:19
A constructor is a method that runs
when you instantiate the class.
0:24
And again, instantiation happens when you
create a new instance of the class
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