Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Trouble understanding some ideas regarding encapsulation  RSS feed

 
henry xiao
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, I'm currently reading up on Daniel Liang's Intro to java and am starting to get a bit confused on chapt. 10: class abstraction & encapsulation. In an example class called "Loan", it has your normal "get" and "set" methods to do certain things that pertain to loans, but at the beginning I'm confused to why the declarations are all "private". Sorry if I'm explaining this poorly.

After these declarations, you have your setters and getters. Why are they private if their values are changed?
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The data members themselves are private, so they are not directly manipulable from outside the class, but getter and setter methods might be available.

It is usual to have this situation.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!