Python Programming - Inheritance - Discussion

Discussion Forum : Inheritance - General Questions (Q.No. 97)
97.
Consider the following code:
class Book:
    def __init__(self, title, author):
        self.title = title
        self.author = author

class EBook(Book):
    def __init__(self, title, author, format_type):
        super().__init__(title, author)
        self.format_type = format_type
What is the primary advantage of using super().__init__(title, author) in the EBook class constructor?
To call the constructor of the EBook class
To create a new instance of the Book class
To initialize attributes of the Book class in the EBook class
To access superclass attributes directly
Answer: Option
Explanation:
super().__init__(title, author) is used to call the constructor of the superclass Book and initialize the title and author attributes.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.