Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

regarding Java Beans  RSS feed

 
yekkala krishna
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why the fields in java beans are make as private ?

what is the problem we will get if we make it as public ?

I have an idea regarding java bean i.e., set and get methods for the fields in the database...i.e., private fields and public set and get methods ?

But i want the solution for why we make fields as private?
 
Manuel Leiria
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It�s an OO principle called encapsulation.

Check this link for details

http://www.javaworld.com/javaworld/jw-05-2001/jw-0518-encapsulation.html
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Going ahead to what Manuel Leiria said , you can also look into Mutator Methods.

You could have posted this question in some other more appropriate forum (May be , Java in General) for better responses.
[ July 16, 2007: Message edited by: Rahul Bhattacharjee ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!