0% found this document useful (0 votes)
12 views10 pages

INHERITANCE

Inheritance is a key concept in object-oriented programming where a subclass derives properties and methods from a parent class. There are several types of inheritance including single, multiple, multilevel, hierarchical, and hybrid. Each type demonstrates different relationships between classes and how they can share functionality.

Uploaded by

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

INHERITANCE

Inheritance is a key concept in object-oriented programming where a subclass derives properties and methods from a parent class. There are several types of inheritance including single, multiple, multilevel, hierarchical, and hybrid. Each type demonstrates different relationships between classes and how they can share functionality.

Uploaded by

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

INHERITANCE

By Riya Shikha
what is inheritance
inheritance is a fundamental concept in object-oriented
programming (OOP) where a class (called a child or
subclass) derives properties and behaviors (methods
and attributes) from another class (called a parent or
superclas
TYPES OF
INHERITANCE
1) SINGLE

TYPES OF INHERITANCE
2) MUTIPLE
INHERITANCE INHERITANCE
3) MULTILEVEL
INHERITANCE
4) HIERARCHICAL
INHERITANCE
5) HYBRID
INHERITANCE
SINGLE INHERITANCE
1. Single Inheritance
A child class inherits from one parent class.

class Parent:
def show(self):
print("Parent class")

class Child(Parent):
pass

c = Child()
c.show() # Output: Parent class
2) MULTIPLE INHERITANCE 2. Multiple Inheritance
A child class inherits from more than one parent class.

class Father:
def skill(self):
print("Driving")

class Mother:
def skill(self):
print("Cooking")

class Child(Father, Mother):


pass

c = Child()
c.skill() # Output: Driving (depends on method resolution order)
3) MULTILEVEL INHERITANCE
A class is derived from a class that is also derived from another class.
python
class Grandparent:
def speak(self):
print("Grandparent")

class Parent(Grandparent):
passclass Child(Parent):
pass

c = Child()
c.speak() # Output: Grandparent
4. Hierarchical Inheritance
Multiple child classes inherit from the same parent
class.
class Parent:
def show(self):
print("Parent")

class Child1(Parent):
pass

class Child2(Parent):
pass

c1 = Child1()
c1.show() # Output: Parent
5. Hybrid Inheritance
A combination of two or more types of inheritance (like
multiple + multilevel).
class Person:
def info(self):
print("I am a person")

# Intermediate class 1 (inherits from Person)


class Employee(Person):
def employee_info(self):
print("I am an employee")

# Intermediate class 2
class Student(Person):
def student_info(self):
print("I am a student")

# Derived class (inherits from both Employee and


Student)
class Intern(Employee, Student):
def intern_info(self):
print("I am an intern")

# Creating object
intern = Intern()
intern.info() # From Person
intern.employee_info() # From Employee
intern.student_info() # From Student
intern.intern_info() # From Intern
THANK YOU

You might also like