Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects (Retired) Meet Objects Privacy and Methods

Randy Cole
PLUS
Randy Cole
Courses Plus Student 2,494 Points

Does a property have to be get or set?

I'm wondering since methods expose the behavior of objects can they include properties which are more specific than just get or set, can they also be something like change or increase (like increaseRadioVolume)?

1 Answer

Hi Randy,

Absolutely, yes, methods can be used to modify member variables in any way you like - and you chose a great example there.

Getting and setting is a key learning to demonstrate the importance of private member variables etc. But the methods allowed access to such private variables can do anything at all to them.

Good question; I hope my attempted answer helped.

Steve.

Thanks Steve, I wanted to know that also.

Randy Cole
Randy Cole
Courses Plus Student 2,494 Points

That's a relief because it makes it a lot easier to understand how the methods relate to each instance... thanks you were definitely a help I really appreciate the clarity Steve