Learn
Introduction to Classes
This Looks Like a Job For...
On the flip side, sometimes you’ll be working with a derived class (or subclass) and realize that you’ve overwritten a method or attribute defined in that class’ base class (also called a parent or superclass) that you actually need. Have no fear! You can directly access the attributes or methods of a superclass with Python’s built-in super
call.
The syntax looks like this:
class Derived(Base): def m(self): return super(Derived, self).m()
Where m()
is a method from the base class.
Instructions
1.
First, inside your PartTimeEmployee
class:
- Add a new method called
full_time_wage
with the argumentsself
andhours
. - That method should
return
the result of asuper
call to thecalculate_wage
method ofPartTimeEmployee
‘s parent class. Use the example above for help.
Then, after your class:
- Create an instance of the
PartTimeEmployee
class calledmilton
. Don’t forget to give it a name. - Finally,
print
out the result of calling hisfull_time_wage
method. You should see his wage printed out at $20.00 per hour! (That is, for10
hours, the result should be200.00
.)