0% found this document useful (0 votes)
3 views4 pages

Inheritance

Inheritance in programming allows a child class to inherit attributes and methods from a parent class. There are several types of inheritance including single, multiple, multilevel, hierarchical, and hybrid inheritance. Each type demonstrates different relationships between classes, showcasing how they can share functionality.

Uploaded by

SHAHIDHA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Inheritance

Inheritance in programming allows a child class to inherit attributes and methods from a parent class. There are several types of inheritance including single, multiple, multilevel, hierarchical, and hybrid inheritance. Each type demonstrates different relationships between classes, showcasing how they can share functionality.

Uploaded by

SHAHIDHA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

INHERITANCE

Inheritance allows a class (called a child class or subclass) to inherit


attributes and methods from another class (called a parent class or
superclass).

Single Inheritance
Multiple Inheritance
Multilevel Inheritance
Hierarchical Inheritance
Hybrid Inheritance

1. Single Inheritance

A child class inherits from one parent class.

class Animal:
def speak(self):
print("Animal speaks")

class Dog(Animal):
def bark(self):
print("Dog barks")
2. Multiple Inheritance

A child class inherits from more than one parent class.

class Father:
def skills(self):
print("Gardening, Programming")

class Mother:
def skills(self):
print("Cooking, Art")

class Child(Father, Mother):


pass

3. Multilevel Inheritance

A child class inherits from a parent class, and another class


inherits from that child class.

class Grandparent:
def house(self):
print("Grandparent's house")

class Parent(Grandparent):
def car(self):
print("Parent's car")

class Child(Parent):
def bike(self):
print("Child's bike")
4. Hierarchical Inheritance

Multiple child classes inherit from a single parent class.

class Animal:
def eat(self):
print("Eating")

class Dog(Animal):
def bark(self):
print("Barking")

class Cat(Animal):
def meow(self):
print("Meowing")

5. Hybrid Inheritance

A combination of two or more types of inheritance.

class A:
pass

class B(A):
pass

class C(A):
pass

class D(B, C):


pass

You might also like