The encapsulation allows us to handle an object using the following properties:
Read/Write - Here, we use setter methods to write the data and getter methods read that data.
Read Only - In this case, we use getter methods only.
Write Only - In this case, we use setter methods only.
Let's see a simple example of encapsulation that contains two data members with its setter and getter methods.Test it Now
In this example, we validate the marks of the student.Test it Now
Here, we perform prototype-based encapsulation.Test it Now