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 our first method, a getter.
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
It can't even be accessed from
outside the class itself.
0:00
We want to allow consumers of our objects
to still be able to see the value,
0:00
even if they can't change it.
0:04
So how do we let them get the value then,
you ask?
0:06
Great question.
0:09
Well the answer is we build
a method that exposes a value.
0:10
You've used methods before but for
instance on the console object use
0:14
the print F method or on strings
we use the two lower case method.
0:18
Now remember what I said that developers
modeling the real world objects focus on
0:22
two main characteristics
which are state and behavior.
0:26
Well fields usually are used
to express that state and
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