Encapsulation is a programming concept that involves hiding the internal state of an object and exposing only the necessary functionality. In the provided Java example, the 'Person' class encapsulates the 'name' attribute by making it private and providing public methods to set and get its value. This ensures that the internal representation of the object is protected from direct access and modification.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
7 views1 page
7 Explain Encapsulation With Example
Encapsulation is a programming concept that involves hiding the internal state of an object and exposing only the necessary functionality. In the provided Java example, the 'Person' class encapsulates the 'name' attribute by making it private and providing public methods to set and get its value. This ensures that the internal representation of the object is protected from direct access and modification.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1
Explain Encapsulation with Example
Encapsulation means hiding internal details and showing only functionality.
Example in Java: ```java class Person { private String name; public void setName(String name) { this.name = name; } public String getName() { return name; } } ```