Python Developer Question:

Explain me inheritance in Python with an example?

Tweet Share WhatsApp

Answer:

Inheritance allows One class to gain all the members(say attributes and methods) of another class. Inheritance provides code reusability, makes it easier to create and maintain an application. The class from which we are inheriting is called super-class and the class that is inherited is called a derived / child class.

They are different types of inheritance supported by Python:

☛ Single Inheritance – where a derived class acquires the members of a single super class.
☛ Multi-level inheritance – a derived class d1 in inherited from base class base1, and d2 is inherited from base2.
☛ Hierarchical inheritance – from one base class you can inherit any number of child classes
☛ Multiple inheritance – a derived class is inherited from more than one base class.

Download Python Developer PDF Read All 77 Python Developer Questions
Previous QuestionNext Question
Tell me how Memcached should not be used in your Python project?Tell me what is Flask & its benefits?