How to implement inheritance in python?

Description

To implement inheritance in python3.

Inheritance:

   Like other object oriented language
python also does inheritance.

   To create new class from base class
stats and behaviour.

   Base class act as like parent class.

   Inherited class act like child class.

   It gives the the oops concept of
re usability.

Syntax(simple inheritance):

class BaseClass:

Body of base class

class DerivedClass(BaseClass):

Body of derived class

#Parent class
class car:

#parent class method
def models(self):
print(‘Four wheel’)

#child class
class bike(car):

#child class method
def model(self):
print(‘Two wheeler’)

#object creation for child class
a=bike()

#call parent class method using child class object
a.models()
a.model()

Leave Comment

Your email address will not be published. Required fields are marked *

clear formSubmit