wood burning stoves 2.0*
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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

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??

Siddhesh Deodhar
Ranch Hand

Joined: Mar 05, 2009
Posts: 117
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%] )
I agree. Here's the link: http://aspose.com/file-tools
subject: Java Class with all attribute as public
Similar Threads
get and set??
Problem while Join in hibernate
Encapsulation & Information Hiding and Inheritence
bean and jstl question
Data Transfer Object query