Skip to content

Latest commit

 

History

History
55 lines (39 loc) · 1.96 KB

README.md

File metadata and controls

55 lines (39 loc) · 1.96 KB

Super Lab

Learning Goals

  • Practice using super to extend child class functionality

Introduction

In this lab we're going to practice the two most common usages of the super keyword.

Instructions

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 named species.
  • 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.

Define a Deciduous class that extends Tree:

  • A Deciduous instance takes two parameters, species and name. Use super() in the constructor to use the parent class constructor to assign species. After super(), assign the name parameter to the a name property in the Deciduous constructor
  • Create a static method, definition(), that uses super to access definition() from Tree and add the following to the provide a specific definition for Deciduous:
Deciduous trees shed their leaves annually.

Define a Evergreen class that extends Tree:

  • An Evergreen instance takes two parameters, species and name. Use super() in the constructor to use the parent class constructor to assign species, then assign name to a property in the Evergreen constructor
  • Create a static method, definition(), that uses super to access definition() from Tree and add the following to the provide a specific definition for Evergreen:
Evergreens keep their leaves all year round.

Resources