What is encapsulation in java

DWQA QuestionsCategory: QuestionsWhat is encapsulation in java
1 Answers
Editor Staff answered 3 weeks ago

The idea behind encapsulation is to hide the implementation details from users. If a data member is private it means it can only be accessed within the same class. No outside class can access private data member (variable) of other class.
However if we setup public getter and setter methods to update (for example void setName(String Name ))and read (for example String getName()) the private data fields then the outside class can access those private data fields via public methods.