❮ Previous Next ❯

Python Inheritance


What Is Inheritance


Inheritance is an important feature of Object Oriented Programming(OOP).

It is a process where the properties of one class is transferring to another class.

The properties are transferring from which class is known as super or parent class.

The class which inherits the properties from super class is known as child or sub class.

It provides the concept of re-usability, which is the main advantage of inheritance.

In inheritance context, through the child(sub) class object we access super class and sub class properties.

Python Inheritance Example

Let's see a simple python inheritance example where we are using two classes: Vehicle and Car. Vehicle is the parent or base class and Car is the child class.


Here, we are defining run() method in Vehicle class and move() method in Car class. In this example, we are creating instance of Car class and calling run() and move() methods by the instance of child class only. Since, parent properties and behaviors are inherited to child object automatically, we can call parent and child class methods by the child class instance only.

Example:

python inhertance1
python inhertance1
❮ Previous Next ❯

Follow Us




  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved