- Practice using
super
to extend child class functionality
In this lab we're going to practice the two most common usages of the super
keyword.
-
Define a
Tree
class that will act as our parent.- A
Tree
instance should take in one parameter when created,species
, and assign this to a property namedspecies
. - A
Tree
should have a static method,definition()
, that returns a short definition of all trees.
A tree is a perennial plant with an elongated stem, or trunk, supporting branches and leaves.
- A
-
Define a
Deciduous
class that extendsTree
- A
Deciduous
instance takes two parameters,species
andname
. Usesuper()
in the constructor to use the parent class constructor to assignspecies
. Aftersuper()
, assign thename
parameter to the aname
property in theDeciduous
constructor - Create a static method,
definition()
, that usessuper
to accessdefinition()
fromTree
and add the following to the provide a specific definition forDeciduous
:
Deciduous trees shed their leaves annually.
- A
-
Define a
Evergreen
class that extendsTree
- An
Evergreen
instance takes two parameters,species
andname
. Usesuper()
in the constructor to use the parent class constructor to assignspecies
, then assignname
to a property in theEvergreen
constructor - Create a static method,
definition()
, that usessuper
to accessdefinition()
fromTree
and add the following to the provide a specific definition forEvergreen
:
Evergreens keep their leaves all year round.
- An