Editor

Abstract Property: Employee Types

Advanced · Write the code · from Python Abstract Base Classes: Enforce Interfaces with ABC

From the lesson: Python Abstract Base Classes: Enforce Interfaces with ABC

Imagine you're an architect handing blueprints to a construction crew. The blueprint says "there must be a front door here" and "the roof goes here." The crew can choose the materials and style, but they must include those parts. If they skip the front door, the building inspector will reject the project.

Read the lesson

Create an abstract class Employee with an abstract property role and an abstract method salary(). Then create two subclasses:

  • Engineer where role returns 'Engineer' and salary() returns 95000
  • Manager where role returns 'Manager' and salary() returns 120000
  • Create one of each and print their info in the format: Role: salary

    from abc import ABC, abstractmethod
    # Create Employee ABC, Engineer, and Manager

    More Abstract Base Class exercises

    All Python exercises · 50 practice problems · Object-Oriented Programming quiz