OOP Python Code — Polymorphism

class Employee:
    def __init__(self, fname, lname):  # CONSTRUCTOR called for each INSTANTIATION
        self.firstname = fname
        self.lastname = lname

    def printname(self):
        print(self.firstname, self.lastname)

    def pay(self):
        print(
            "Pay will depend on if the employee is hourly, salaried, or commissioned."
        )


class Hourly(Employee):
    def pay(self, hours, rate):
        return hours * rate


nHP = Hourly("Ashanti", "Patel")
payCheck = nHP.pay(36, 17.50)
print(payCheck)

# Knowledge Check #4: use polymorphism to override pay in Salary

Leave a Reply