Lesson 50 of 55
9 mins readPython OOP Inheritance & Method Overriding
In Plain English
Perl supports class inheritance using `use parent "BaseClass";` (which populates the special `@ISA` array). Derived classes can override methods and inherit base behavior.
Deep Dive: How It Works
@ISA Array: Holds the list of parent packages Perl searches when dispatching methods.
use parent: Modern pragma that automatically configures `@ISA`.
SUPER:: Pseudo-Class: Calls the parent class implementation of an overridden method: `$self->SUPER::method()`.
Core Rules to Remember

use parent Pragma: Declares class inheritance cleanly.

SUPER:: Dispatch: Invokes the parent class method from an overriding subclass.
Live Interactive Example
Hit Run Code to see it liveClass Inheritance and Method Overriding
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Output Console
Click "Run Code" to view the rendered output.
How it works: Developer inherited the constructor from Worker and overrode do_work().
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Inherit and Call Base Constructor
Create a base class `Animal` with `sub speak { "Sound" }`.
Create `Dog` inheriting via `our @ISA = qw(Animal);` with `sub speak { "Woof" }`.
Print `"Dog says: " . Dog->speak() . "\n"`.
1
2
3
4
5
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.