Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

The way I have understood encapsulation is 

 

“It is a mechanism to hide information from the client. The information may be data or implementation or algorithm. We achieve this using access modifiers.

 

It’s more like data hiding. I want to know how do we achieve encapsulation in Java other than ‘Access Modifiers’? 

1 Answer

0 votes
by (19.7k points)

Encapsulation is bundling the data with the operations you perform on that data. It encapsulates the data - fields and methods for manipulation of data. 

The bundling of data and methods is to hide the implementation which sounds more like data hiding as you say.  

But a  better way than to use methods and make all fields private is interfaces. It provides a total abstraction. The object which will be created is based on the class which is implementing the interface. This way it hides all the fields and methods internally. 

If you want to learn more about Java? Check this out: Java course on Intellipaat    

Related questions

0 votes
1 answer
0 votes
1 answer
asked Mar 11, 2020 in Java by Sudhir_1997 (55.6k points)
0 votes
1 answer
asked Mar 2, 2021 in Java by rahulnayar01123 (6.1k points)
0 votes
1 answer

Browse Categories

...