This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Set and get Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Set and get" Watch "Set and get" New topic
Author

Set and get

David Starr
Ranch Hand

Joined: Apr 08, 2013
Posts: 54
Feel free to enhance or correct these statements: From my understanding the setter and getter are set as private and separate due to protection from being altered and ease in updating. This is done over hard-coding the values (in this case) of 70 and 8. It seems like more code to do this verses simply hard-coding. Also, if a method is termed as 'void' how come the void bark() method is returning some print statements?



===========
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30392
    
150

Welcome to CodeRanch!

David Starr wrote:Feel free to enhance or correct these statements: From my understanding the setter and getter are set as private and separate due to protection from being altered and ease in updating.

The instance variable is private. The setter and getter are public. If you search for "encapsulation", you can read about why protection from alteration is useful. My favorite is that you can add validation.

David Starr wrote: Also, if a method is termed as 'void' how come the void bark() method is returning some print statements?

Bark isn't returning a print statement. It is calling a print statement. Just like your main method is calling setSize() and System.out.println(). Any method can call other methods. Only methods with a return type can return a value.
David Starr
Ranch Hand

Joined: Apr 08, 2013
Posts: 54
Thank you. It seems to make sense. The code itself came from a textbook, but I will need to understand this more. I suppose I just need to keep looking over it and getting more repetition. Thank you again.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38509
    
  23
And welcome to the Ranch
David Starr
Ranch Hand

Joined: Apr 08, 2013
Posts: 54
Thank you. I am honored to be included.

Sincerely,
David
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Set and get