Subclass-only methods

Beginner Python OOP Inheritance
Created by Pavel · 07.03.2026 at 19:57 UTC · 5 completed

You inherit everything the parent exposes, then you teach the child something the parent never knew how to do. That is the everyday meaning of extending a class: shared core, plus behaviour that only makes sense for the specialised type.

The catch is that students still interact through the same mental model—report.generate() stays familiar—while show_plot() appears only where visual tooling exists. If you forget that new methods live only on the subclass, you will try to call them from a plain base reference and get an attribute error, even when inheritance is otherwise correct.

University approvals: 0
Tasks
Question 1

Is it allowed for a subclass to define methods that the parent class does not have?

Hint

Inheritance supports extension

Question 2

Write a standalone script. Define Report with generate(self) that prints exactly Standard report.
Define VisualReport(Report) with show_plot(self) that prints exactly Displaying bar chart.
Then create r = VisualReport(), call r.generate(), then r.show_plot().

Grading uses stdout (no extra lines). Runner: CPython in the default Studdyco sandbox.

Hint

Match the two print strings exactly; call both methods.

Starter code is prefilled; replace TODO blocks with your solution.
1 test case will be used for grading
Run checks runtime behavior only. Final correctness is evaluated when you submit.
Card Info
  • Topic: Python OOP Inheritance
  • Difficulty: Beginner
  • Completed: 5 users
Creator
Pavel
Pavel