Question: In Module 3 . 2 we introduced a concept called 'inheritance'. Inheritance models an is - a relationship, so when you have a

In Module 3.2 we introduced a concept called 'inheritance'. Inheritance models an "is-a" relationship, so when you have a subclass that inherits from a parent class, you create a relationship where the subclass is a specialized version of the base class. For instance, an animal is a generalization of dog,shark,tiger, "cat" and many others. So "animal" is an abstraction of "dog", "shark", etc., and since "dogs" are "animals" they inherit all the properties common to all "animals", such as eating, sleeping and playing.
In Python, we can define classes that inherit the behaviors of other classes. To practice this OOP design principle, let's consider real numbers as special cases of complex numbers; they are just the numbers x + yi when y is 0, that is, they're the numbers on the real axis. For instance, the real number 2 is 2+0i.
In the same file where you have your Complex class, create the class Real, a subclass of Complex, run the code, and execute the last 2 statement in the Python Shell. Check the output displayed by print(x), what does the line super().__init__(value,0) do in the constructor of the Real class?
class Real(Complex):
def __init__(self, value):
super().__init__(value,0)
>>> x=Real(3)
>>> print(x)
________________
Group of answer choices
It initializes the attributes self._real = value and self._imag =0
Class definition is incorrect
It creates and defines the constructor of the Real class
It defines a Complex object to use in the Real class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!