Sunday 2-5 Class Topics:
==> Pillars of Object-Oriented Programming (OOP)
OOP is based on four main pillars that help in building modular, reusable, and
organized code.
- Encapsulation
-Definition:
==> Encapsulation is the process of wrapping data (variables) and code (methods)
together as a single unit (class), and restricting access to some of the object's
components.
Key Points:
Achieved using access modifiers (private, public, protected)
Keeps internal data safe from unintended access
Promotes data hiding.
Example:
class Student:
    def __init__(self, name):
        self.__name = name # private attribute
    def get_name(self):
        return self.__name
2. Inheritance
Definition:
Inheritance allows a class (child/subclass/Derived) to acquire properties and
methods from another class (parent/superclass/Base).
Key Points:
Promotes code reusability
Supports hierarchical classification
Example:
class Animal:
    def speak(self):
         print("Animal speaks")
class Dog(Animal):
    def bark(self):
        print("Dog barks")
3. Polymorphism
Definition:
Polymorphism means "many forms". It allows the same method to perform different
behaviors depending on the object or context.
Types:
Compile-time (Method Overloading) – Not directly supported in Python
Runtime (Method Overriding) – Supported in Python
Example:
class Animal:
    def sound(self):
        print("Animal sound")
class Cat(Animal):
    def sound(self):
        print("Meow")
4. Abstraction
Definition:
Abstraction means hiding complex implementation details and showing only the
essential features of the object.
Key Points:
Focuses on what an object does, not how it does it
Can be achieved using abstract classes or interfaces
Example:
from abc import ABC, abstractmethod
class Shape(ABC):
    @abstractmethod
    def area(self):
        pass
class Circle(Shape):
    def area(self):
        return 3.14 * 5 * 5
Preapred By:
Faqeha Noor