Get startedGet started for free

Implementing Abstract Base Classes

Now that you've built the Company abstract base class, it can be used as a "blueprint" for different companies. You'll practice doing just this by creating a Technology class.

The Company class from the previous exercises has been defined for you, and looks like this:

class Company(ABC):
  @abstractmethod
  def create_budget(self):
    pass

  def hire_employee(self, name):
    print(f"Welcome to the team, {name}!")

This exercise is part of the course

Intermediate Object-Oriented Programming in Python

View Course

Exercise instructions

  • Create a Technology class that inherits from the Company abstract base class.
  • Define the create_budget() method with two parameters, year and expenses.
  • Create an instance of the Technology class with name "Tina's Tech Advisors".
  • Call the create_budget() method using the provided arguments; observe the output of this method, as well as hire_employee().

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create a class with the name "Technology"
class ____(____):
  def __init__(self, name):
    self.name = name

  # Define a create_budget() method
  def ____(self, ____, ____):
    for expense, amount in expenses.items():
      print(f"{year} budget for {expense} is {amount}")
  
# Create an instance of the Technology class, call methods
t = ____("____")
t.____(2024, {"Salaries": 10000, "Supplies": 500})
t.____("Christian")
Edit and Run Code