0% found this document useful (0 votes)
5 views

Class Notes - Inheritance

Uploaded by

lavania
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Class Notes - Inheritance

Uploaded by

lavania
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Inheritance in Object-Oriented Programming:

- Definition: Mechanism of basing a class (child class) on another class (parent class).

- Types of Inheritance:

1. Single Inheritance: One child class inherits from one parent class.

2. Multiple Inheritance: A child class inherits from multiple parent classes.

3. Multilevel Inheritance: A class is derived from another derived class.

4. Hierarchical Inheritance: Multiple child classes inherit from a single parent class.

5. Hybrid Inheritance: Combination of two or more types of inheritance.

- Benefits:

- Code Reusability.

- Easy to maintain and extend existing code.

- Example in Python:

```python

class Parent:

def greet(self):

print("Hello from Parent")

class Child(Parent):

def greet_child(self):

print("Hello from Child")

obj = Child()

obj.greet() # Output: Hello from Parent

obj.greet_child() # Output: Hello from Child

```

You might also like