✦ Python Intermediate & OOP Advanced OOP

L2 · Concept 02 · Advanced OOP

Same foundation.
Different behavior.

EBook and PrintedBook keep Book data while adding their own details.

Learning goalUse super() to initialize shared Book data and extend an inherited method.
01 Learn02 Try03 Predict

Learning as a guest

Learning as a guest? Save your progress!

Create a free account to learn with Sloby AI, check your understanding, and track your progress.

The entire platform is free throughout 2026. Foundations stays free forever.

Reuse the parent, then extend it.

Repeating title, author, and year initialization in every child class makes code harder to maintain.

class Book:
    def __init__(self, title, author, year):
        self.title = title
        self.author = author
        self.year = year
        self.is_available = True

    def display_info(self):
        print(f"{self.title} - {self.author}")

class EBook(Book):
    def __init__(self, title, author, year, file_size):
        super().__init__(title, author, year)
        self.file_size = file_size

    def display_info(self):
        super().display_info()
        print(f"File size: {self.file_size} MB")

ebook = EBook("Dune", "Frank Herbert", 1965, 5.2)
ebook.display_info()

super().__init__() calls the parent constructor for shared attributes. EBook then saves file_size. This simplified Book example still represents the full project’s shared behavior.

Dune - Frank Herbert File size: 5.2 MB

Overriding display_info() replaces the inherited method. When we call display_info() on an EBook object, Python uses the method defined in EBook first, if one exists. Calling super().display_info() keeps the parent output before adding new output.

↳

Keep in mind: super() is useful when you want parent behavior too. It is not required for every overridden method.

Override without parent output
class PrintedBook(Book):
    def display_info(self):
        print("Printed edition")

This override prints only its own message because it does not call super().display_info().

Python Playground

Loading Python runtime…

Run the EBook example, then complete PrintedBook in the mini challenge.

super_overriding.pyPython
OutputWaiting for Python
The browser runtime is loading. You can still edit the example code.

Pyodide runs Python in a browser Web Worker. It is stopped and restarted if code keeps running. Browser execution is not a complete security boundary; do not enter secrets or rely on it for untrusted code isolation.

What will this program print?

PrintedBook overrides display_info() without calling the parent method.

class Book:
    def __init__(self, title, author, year):
        self.title = title

    def display_info(self):
        print(f"{self.title} - Frank Herbert")

class PrintedBook(Book):
    def display_info(self):
        print("Printed edition")

book = PrintedBook("Dune", "Frank Herbert", 1965)
book.display_info()
Choose the output

Practice independently

Mini Challenge — Extend PrintedBook

Add pages and extend the inherited display method.

Your goalUse super().__init__(), save pages, then print the inherited information and page count.

printed_book.py

Optional hints
  • Call super().__init__(title, author, year) before saving pages.
  • Call super().display_info() before printing Pages.
Ask Sloby for a hint
Sloby, the Python AI Tutor mascot

Your learning mentor

Sign in to ask Sloby

Create a free account or sign in to get AI guidance while you learn.

Sign in to check your understanding

Create a free account or sign in to receive AI feedback and save your learning progress.

Python AI Tutor · Learn by understanding, not just by running code.