WhatsApp and Telegram Group Card
WhatsApp Group Join Now
Telegram Group Join Now

Inheritance in Python – OOPS Concepts

As we know, there are some concepts of OOPs (that stands for Object Oriented Programming). Here In this article of Inheritance in Python, we have discussed about an important concept of OOPS that is Inheritance, Hope you will enjoy this article and get to know about some basics of Inheritance.

Inheritance in Python : –

As like inheritance in other OOPS Languages same in Python also “The process of accessing the one class from another class is known as Inheritance. Means in this definition those two classes are namely knows as Parent Class and Child Class.

1. Parent Class :-

The class that inherits or access the property of another class is known as Parent Class. It is also known as Base Class.

2. Child Class : –

The class that inherits from another class is known as Child class. It is also called as derived class.

Syntax of inheritance : –
class BaseClass :
    {Body}
class DerivedClass(BaseClass):
    {Body}
Implementation of inheritance : –
class Person(object):
# Constructor
    def __init__(self, name):
    self.name = name
    # To get name
    def getName(self):
    return self.name
    # To check if this person is an employee
    def isEmployee(self):
     return False

# Inherited or Subclass (Note Person in bracket)
class Employee(Person):
    # Here we return true
    def isEmployee(self):
    return True

# Driver code
emp = Person("Geek1") # An Object of Person
print(emp.getName(), emp.isEmployee())
emp = Employee("Geek2") # An Object of Employee
print(emp.getName(), emp.isEmployee())

Hope, after going through the whole article, all your doubts are cleared related Inheritance in Python.

Kindly, visit the Articles for more.

In case of any query, Please feel free to contact us.

Kindly share it with your friends.

Regards, EduPaat Team