OOP Python Code — Inheritance

# Add another method to the Employee class for pay
class Employee:
    def __init__(self, fname, lname):
        self.firstname = fname
        self.lastname = lname
        # self._salaray = 500

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

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


newHire = Employee("Tina", "Majchrzak")
# newHire.pay()

# Extend the PARENT Employee class by deriving a CHILD Hourly class from it


class Hourly(Employee):
    pass


newHourlyPerson = Hourly("Dakota", "Chen")
print(newHourlyPerson.firstname)
newHourlyPerson.pay()

# Knowledge Check #3: create another child class derived from Employee called Salary

Leave a Reply