This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes Java Class with all attribute as public Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Java Class with all attribute as public" Watch "Java Class with all attribute as public" New topic
Author

Java Class with all attribute as public

Kumar Gaurav
Ranch Hand

Joined: Apr 08, 2008
Posts: 108
Hi All,

My question is what is the need of declaring all the variables of a java class as private and declearing their setter and getter as public.
Instead we can declare all variables as public which will eliminate the need of having public getter and setter.

is there any valid reason??


Regards,
Gaurav
Siddhesh Deodhar
Ranch Hand

Joined: Mar 05, 2009
Posts: 118
Google "why to use getter setters" you will get many articles explaining object oriented concepts and their needs.
You can check this for quick reference.


Good, Better, Best, Don't take rest until, Good becomes Better, and Better becomes Best.
Sidd : (SCJP 6 [90%] )
 
GeeCON Prague 2014
 
subject: Java Class with all attribute as public