File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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:
subject: Java Class with all attribute as public
Similar Threads
get and set??
bean and jstl question
Encapsulation & Information Hiding and Inheritence
Data Transfer Object query
Problem while Join in hibernate