Private methods cannot be accessed by other files You might want a private method because it manages complexity for the person using the method
Encapsulation is the process of hiding implementation details . encapsulation is one of the core tenants of object oriented programming.
Encapsulation is different than abstraction because it is concerned with hiding the internal state of an object ( stuff like the instance variables ) , whereas Abstraction is concerned with hiding the details of how something works.
Abstraction revolves around you dont need to know encapsulation revolves around you shouldnt know and you dont need to have the data from me
if we didnt make instance variables private their internal values could be changed easily from other files
public instance variables can be accessed directly System.out.println(rect.width)
private instance variables stop users from breaking things we use accessor and mutator methods ( getter and setter methods ) to control what aspects of an object can be altered
Programmers have to chose whether data should be accessible modifiable both or neither.
savings account methods you would want access to : deposit() withdraw() checkbalance() ( or tostring()) logout() login() signup() deleteaccount() invest() gethistory()
Some methods users dont need: addInterest() daysOpen()
setting methods to private does no tmean that we don’t trust users, its simply that they dont need access to those methods in order to implement the class correctly