LESSON 4 Flashcards
- One of the core concepts in object-oriented programming is inheritance.
●It is a mechanism that allows you to create a hierarchy of classesthat share a set of properties and methods by deriving a class from another class.
●_____ is the capability of one class to derive or inherit the properties from another class.
Inheritance
the class whose features are inherited by other classes
Super Class (Parent/Base Class)
The class that inherits the features of other classes. ___ __ can also have their own features in addition to the inherited ones.
Sub class (Child Class)
The concept where we can derive a new class from existing classes
Reusability
allows you to inherit the properties of a class, i.e., base class to another, i.e., derived class.
Inheritance
The benefits of Inheritance in Python are as follows
●It represents real-world relationships well.
●It provides the reusability of a code. We don’t have to write the same code again and again. Also, it allows us to add more features to a class without modifying it.
●It is transitive in nature, which means that if class Y inherits from another class X, then all the subclasses of Y would automatically inherit from class X.
●Inheritance offers a simple, understandable model structure.
●Less development and maintenance expenses result from an inheritance.
●To further understand this mechanism of OOP, we use the IS-A relationship, where we create a subclass by including the name of the parent class as a parameter
Inheritance
●A child class needs to identify which class is its parent class.
●This can be done by mentioning the parent class namein the definition of the child class.
●In order to properly use the attributes of the parent class, you must either:
●Invoke the constructor of the parent class
●Do not create a constructor for the subclass and use Getters and Setters instead.
●Invoke the constructor of the parent class
Subclassing
to access the parent’s class methods and functions.
super() function
If you forget to invoke the __init__() of the parent class then its instance variables would not be available to the child class (True or False)
True
Types of Inheritance
●Single Inheritance
●Multiple Inheritance
●Multilevel Inheritance
●Hierarchical Inheritance
●Hybrid Inheritance
●In __ ___, features of the base class and the derived class are further inherited into the new derived class.
●This is similar to a relationship representing a child and a grandfather.
multilevel inheritance
●When a class is derived from more than one base class, this type of inheritance is called
●In __ ___, all the features of the base classes are inherited into the derived class.
multiple inheritance
enables a derived class to inherit properties from a single parent class, thus enabling code reusability and the addition of new features to existing code.
Single inheritance
When more than one derived class are created from a single base, this type of inheritance is called ___ ___.
●In this program, we have a parent (base) class and two or more child (derived) classes.
hierarchical inheritance