Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help - private nested interface

 
Yan Bai
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not quite understand what the advantage is with the private accessibility. Please give some code examples, Thanks!!
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just think that you will have to be a little more specific. That is, you provide the examples and we will think about them.
-Barry
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The private members are not accessable from outside the class. So if you need to change a private member, all you have to wory about the other members of same class that are accessing it. So the code enhancement and maintenance is much easy. Compare that to a public member that could be called by any other member of any class. So to change that, you will have to possibly change all calling members. In nutshell, private modifier allows you to implement information hiding principle.
Thanks
Barkat
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Encapsulation: by making fields private and methods public the state of the object cannot be accessed directly by anyone. But through the methods. They are responsible for checking that changes in the state don't cause the object to go to an inconsitent state.
For instance, a color field in a traffic lights object cannot be set to pink.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic