0

What is encapsulation?

Iam not getting the idea about encapsulation help me

20th Nov 2016, 7:34 AM
Mirza Azeem Baig
Mirza Azeem Baig - avatar
1 Answer
+ 3
Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit. In encapsulation, the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class. Therefore, it is also known as data hiding. To achieve encapsulation in Java − Declare the variables of a class as private. Provide public setter and getter methods to modify and view the variables values.
20th Nov 2016, 7:45 AM
sanket jain
sanket jain - avatar