PYTHON INHERITANCE | QA SDET | TEST AUTOMATION
🟦 What is Inheritance?
Inheritance allows one class (child) to acquire properties and methods of another class (parent).
---
🔸 Types of Inheritance:
1. Single Inheritance – One child, one parent
2. Multiple Inheritance – Child inherits from multiple parents
3. Multilevel Inheritance – Chain of inheritance
4. Hierarchical Inheritance – One parent, multiple children
5. Hybrid Inheritance – Combination of multiple types
---
✅ Syntax:
class Parent:
def greet(self):
print("Hello from Parent")
class Child(Parent):
def say_hi(self):
print("Hi from Child")
---
🔁 Using Inherited Methods:
c = Child()
c.greet() # Inherited from Parent
c.say_hi() # Defined in Child
---
🔄 Method Overriding:
Child can override a parent method:
class Child(Parent):
def greet(self):
print("Hello from Child") # Overrides Parent.greet
---
🔹 super() Function:
Used to call the parent class’s methods/constructor.
class Parent:
def __init__(self):
print("Parent init")
class Child(Parent):
def __init__(self):
super().__init__() # Calls Parent's __init__
print("Child init")
Видео PYTHON INHERITANCE | QA SDET | TEST AUTOMATION канала Viplove QA - SDET
Inheritance allows one class (child) to acquire properties and methods of another class (parent).
---
🔸 Types of Inheritance:
1. Single Inheritance – One child, one parent
2. Multiple Inheritance – Child inherits from multiple parents
3. Multilevel Inheritance – Chain of inheritance
4. Hierarchical Inheritance – One parent, multiple children
5. Hybrid Inheritance – Combination of multiple types
---
✅ Syntax:
class Parent:
def greet(self):
print("Hello from Parent")
class Child(Parent):
def say_hi(self):
print("Hi from Child")
---
🔁 Using Inherited Methods:
c = Child()
c.greet() # Inherited from Parent
c.say_hi() # Defined in Child
---
🔄 Method Overriding:
Child can override a parent method:
class Child(Parent):
def greet(self):
print("Hello from Child") # Overrides Parent.greet
---
🔹 super() Function:
Used to call the parent class’s methods/constructor.
class Parent:
def __init__(self):
print("Parent init")
class Child(Parent):
def __init__(self):
super().__init__() # Calls Parent's __init__
print("Child init")
Видео PYTHON INHERITANCE | QA SDET | TEST AUTOMATION канала Viplove QA - SDET
Комментарии отсутствуют
Информация о видео
24 мая 2025 г. 15:59:40
00:00:06
Другие видео канала