Computer Science, asked by TbiaSamishta, 1 year ago

What is Encapsulation? Why do we do it?

Answers

Answered by tanishka1578
0

Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit.

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.

Thanks!

Answered by Secondman
0

"     Encapsulation is the wrapping mechanism which implements the concept of abstraction and prevents the data from unauthorized access.

Encapsulations used to prevent the data from unauthorized/ invalid access by implementing proper wrapping mechanisms on the data.

   Encapsulation is also used to hide the complexity of a system/module to make things easier for the user or to make the debugging/development easier for the programmer.

Encapsulation allows the development of secure and modular applications."

Similar questions