• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Set and get

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?



===========
 
author & internet detective
Posts: 39348
755
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 64710
226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
David Starr
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I am honored to be included.

Sincerely,
David
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!