Fred Agbo
November 2, 2026
GrtN9
class Employee:
def __init__(self, name):
self.name = name
def introduce(self):
return f"Hi, I'm {self.name}."
class Manager(Employee):
def approve_request(self):
return f"{self.name} approved the request."
manager = Manager("Sam")
print(manager.introduce())
print(manager.approve_request())
class Employee:
def describe_role(self):
return "I work at the company."
class Manager(Employee):
def describe_role(self):
return "I manage a team."
worker = Employee()
manager = Manager()
print(worker.describe_role())
print(manager.describe_role())
super() Calls Parent Behaviorsuper() gives a subclass access to
methods from its parent class.super().__init__(...) to initialize
the parent’s attributes instead of repeating that code.class Employee:
def __init__(self, name):
self.name = name
class Manager(Employee):
def __init__(self, name, team_size):
super().__init__(name)
self.team_size = team_size
manager = Manager("Sam", 4)
print(manager.name, manager.team_size)
super()super().method_name(...) from the
child’s method.class Employee:
def describe_role(self):
return f"{self.name} works at the company."
class Manager(Employee):
def __init__(self, name, team_size):
super().__init__(name)
self.team_size = team_size
def describe_role(self):
description = super().describe_role()
return f"{description} They lead {self.team_size} people."
manager = Manager("Sam", 4)
print(manager.describe_role())
Pet class that stores a
name and has a speak method.Dog subclass that uses
super() to initialize the name.speak so a dog says
Woof!.print(dog.name, dog.speak()) display?class Pet:
def __init__(self, name):
self.name = name
def speak(self):
return "..."
class Dog(Pet):
def __init__(self, name):
super().__init__(name)
def speak(self):
return "Woof!"
dog = Dog("Milo")
print(dog.name, dog.speak())
super() in a child
constructorBankAccount has an owner and a
balance.SavingsAccount that reuse the
parent’s setup, add an interest rate, and report its account type.describe() in the child by extending the
parent’s description with super().Vehicle
class, which tracks several attributes and includes an initial
__repr__ methodBoat class that inherits
from Vehicle"water"__repr__ method to
correctly print out command needed to create the new boat objects. So it
should return something like "Boat(5000)",
if 5000 was the weight.Carrier class that inherits
from boatcapacity (integer) which should be
provided when a carrier is createdonboard list which tracks what planes
are currently onboard. It always starts empty when the carrier is
created.__repr__ method to
correctly print out command needed to create the new Carrier objects. So
it should return something like
"Carrier(8000, 3)", if 8000 was the weight,
and it had a capacity for 3 planesCarrier class of
add_plane, which accepts a plane’s weight as
an argument
"Deck full!"