Python Programming - Classes - Discussion

Discussion Forum : Classes - General Questions (Q.No. 34)
34.
Consider the following Python 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

# Create an instance of the EBook class
my_ebook = EBook("Python Basics", "John Doe", "PDF")

# Access and print attributes
print(my_ebook.title)
print(my_ebook.author)
print(my_ebook.format_type)
What will be the output of the code?
Python Basics \n John Doe \n PDF
PDF \n Python Basics \n John Doe
Python Basics \n PDF \n John Doe
John Doe \n Python Basics \n PDF
Answer: Option
Explanation:
The code creates an instance of the `EBook` class and prints the values of its attributes (`title`, `author`, `format_type`).
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.