Encapsulation in java

Encapsulation is one of the four fundamental OOP concepts. Remaining three are inheritance, polymorphism, and abstraction.In the previous post, we have studied the Abstract class and interface.

In this post, we will focus on encapsulation.

Encapsulation controls the access to a particular class from outside world i.e. outside classes. We can make a class full encapsulated by making its data-members private.

The possible way to access those data-members or methods will be to make them public getter and setter in the class.

These set and get methods will be used to access the data.In this way, we can make the class Read-Only and Write Only.

Output: Book name is java book
Ask Question
If you have any question, you can go to menu ‘Features -> Q&A forum-> Ask Question’.Select the desired category and post your question.
Print Friendly, PDF & Email
Abstract class and Interface
Call by value in java
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *