Deep_OOP_Concepts_Notes_Extended
Deep_OOP_Concepts_Notes_Extended
2. The class uses the `class` keyword followed by the class name.
4. Objects access attributes and methods using the dot (`.`) operator.
7. Attributes can be defined inside the constructor or directly inside the class.
9. Class variables are shared across all objects; instance variables are specific to each object.
Example:
class Student:
self.roll = roll
def display(self):
s1 = Student("Prince", 101)
s1.display()
1. Method Overloading: Defining multiple methods with the same name but different parameters.
2. Python does not support traditional overloading but can mimic using default or variable arguments.
4. Method Overriding: Redefining a method in the child class with the same name and parameters.
Example:
class Animal:
def sound(self):
print("Animal sound")
class Cat(Animal):
def sound(self):
super().sound()
Advanced OOP Concepts in Python
print("Meow")
4. Use getter and setter methods to access and modify private attributes.
Example:
class BankAccount:
self.__balance = balance
def get_balance(self):
return self.__balance
self.__balance += amount
Example:
class Vehicle(ABC):
@abstractmethod
def start_engine(self):
pass
class Bike(Vehicle):
Advanced OOP Concepts in Python
def start_engine(self):
1. Inheritance allows a class to inherit attributes and methods from another class.
Example:
class Engine:
def start(self):
print("Engine started")
class Car:
def __init__(self):
self.engine = Engine()
Advanced OOP Concepts in Python
def start(self):
self.engine.start()
Example:
class Printer:
def print_doc(self):
class ColorPrinter(Printer):
def print_doc(self):
Advanced OOP Concepts in Python
super().print_doc()
print("Printing in color")