LESSON 4 Flashcards
One of the core concepts in object-oriented programming is inheritance
Inheritance
It is a mechanism that allows you to create a hierarchy of classes that share a set of _____ and _____ by deriving a class from another class
- Inheritance
- properties
- methods
the class whose features are inherited by other classes
SuperClass(Parent/BaseClass)
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
represents real-world relationships well.
Inheritance
Inheritance
- It provides the _____ of a code. We don’t have to write the same code
again and again. Also, it allows us to _______ to a class without
modifying it.
- Inheritance
- reusability
- add more features
which means that if class Y inherits from another class X, then all the subclasses of Y would automatically inherit from class X.
- Inheritance
- transitive in nature
To further understand this mechanism of OOP, we use the ______ , where we create a subclass by including the name of the parent class as a ______
- Inheritance
- IS-A relationship
- parameter
● A child class needs to identify which class is its parent class.
● This can be done by mentioning the parent class name in the definition of the child class.
Subclassing
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.
If you forget to invoke the _______ of the parent class then its instance variables would not be available to the child class
- Subclassing
- __init__()
to access the parent’s class methods and
functions.
- super()function
- Subclassing
five types of inheritance
● Single Inheritance
● Multiple Inheritance
●Multilevel Inheritance
● Hierarchical Inheritance
● Hybrid 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