Python Inheritance and Method Overriding
PCAP objective 4.5 is build a class hierarchy using inheritance. A subclass gets everything its parent has and may replace any of it. super() calls the parent's version, which is how you extend rather than replace. The examinable trap is a subclass __init__ that does not call super().__init__(): the object is created perfectly happily, missing attributes, and fails somewhere else entirely.
Object-Oriented Python Guide 18 of 25 Intermediate
- OSUbuntu 26.04 LTS
- Python3.14.4
- pip25.1.1
- TimeAbout 17 min
super() with no arguments is Python 3 only. The Python 2 form super(Child, self) still works and is never necessary. Both appear in older material.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| RUNNER01 | 192.168.0.27 | Ubuntu 26.04 LTS | Python 3.14.4 - the only machine this path needs | 2 Core | 4 GB | 50 GB |
This guide includes
Use this for the single-inheritance half of the hierarchy objective. This matters because an override replaces the parent's version for that object - and a subclass constructor that forgets its parent leaves the object half-built.
- seeing a subclass get everything, and replace anything
- using
superto extend rather than replace - meeting the constructor that forgets its parent
- finding which class a method was actually found on
- writing polymorphism, which is the point of all of it, and using
isinstanceacross a hierarchy
Before you start
-
A subclass gets everything and can replace anything
-
super, to extend rather than replace
-
The constructor that forgets its parent
-
Which class a method was found on
-
Polymorphism, which is the point of all this
-
isinstance across a hierarchy
-
What the exam does with this objective