Revature interview question

What is Encapsulation? Explain and give an example.

Interview Answers

Anonymous

Jun 21, 2021

Encapsulation is bundling of data with the methods that operate on that data. It is used to hide the values of data objects inside a class, preventing from direct access to them. For example if you make an obj with private acess specifier and want to acces it you cannot access ot directly for this you have to make a public funtion and define it there and then you can use it otherwise you cannot access it

18

Anonymous

Dec 10, 2020

Encapsulation in Java is a process of wrapping code and data together into a single unit. Example: Creating a fully encapsulated class in Java by making all the data members of the class private. Now we can use setter and getter methods to set and get the data in it.

36