Introduction to Encapsulation
Topics
Advertisements
CISCE: Class 10
Introduction to Encapsulation:
Encapsulation, the process of wrapping data and functions together as a unit, can be made possible by declaring the class members private. Once a member method or a member datatype is declared private, it can only be accessed within the class.
Data Hiding
Encapsulation supports data hiding by restricting access to class data members. Private data members are only accessible within their class, ensuring they cannot be used in other classes or the main class, promoting secure data management.
Access Specifier
This defines the visibility of a class method or data.
- Private: Private members are accessed only within the scope of a class.
- Public: Public members can also be accessed outside the class visibility.
- Protected: Protected members are used simply as private members within the class in which they exist but can be accessed to derived class (during inheritance).
