13/18 Override! I dont get anything


#1

Can someone please explain the basic the basic concept of override as I don't get what it means!
-__-
Thanks in advance :smiley:


#2

We are given this class to begin with:

class Employee(object):
    """Models real-life employees!"""
    def __init__(self, employee_name):
        self.employee_name = employee_name
    
    def calculate_wage(self, hours):
        self.hours = hours
        return hours * 20.00

Some of the explanation is provided in the instructions:

Instructions

  • Create a new class, PartTimeEmployee, that inherits from Employee.
  • Give your derived class a calculate_wage method that overrides Employee's. It should take self and hours as arguments.
  • Because
    PartTimeEmployee.calculate_wage overrides Employee.calculate_wage, it still needs to set self.hours = hours.
  • It should return the part-time employee's number of hours worked multiplied by 12.00 (that is, they get $12.00 per hour instead of $20.00).

Notice that the Employee class has a calculate_wage method? Under normal inheritence the PartTimeEmployee class would have access to this method. However, we don't wish to pay a full time wage to a part time employee. By creating a calculate_wage method within this class, it overrides the one in the other that it inherits from. Thus, part time employee wages are calculated at the lower rate.