Encapsulation in Python :
Definition :
- Encapsulation is the concept of restricting direct access to an object’s data and methods to protect data integrity.
Access Modifiers :
- Accessible only within the class.
- Accessible within the class and its subclasses.
- Accessible from anywhere.
Encapsulation without Access Modifiers :
Program:
Encapsulation with Access Modifiers
Private :
Definition: Variables or methods prefixed with are private and not accessible directly
outside the class.
Program:
Output :
Protected :
Definition:
- Variables or methods prefixed with are protected and can be accessed within the class or its subclasses.
Program:
Output :
Public :
Definition :
- Variables or methods without any prefix are public and accessible from anywhere.
Program:
0 Comments