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 create a method that changes the internal state of our object
Learn more
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
Thinking through these limits is always
a good practice to fall into as you
0:00
start modeling objects.
0:01
Now, let's see.
0:03
We wanna store some state, right?
0:04
We wanna store, how many Pez
are actually in the dispenser, right?
0:05
So that's an infield, right?
0:10
And we will name that pezCount.
0:11
And we don't really want anyone
to just change this willy nilly.
0:15
So a good practice for
0:20
that is to keep it private until you have
a reason to expose it to your consumers.
0:21
So we'll make this private.
0:27
Said another way, if you aren't sure,
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