1. Learn
  2. /
  3. Courses
  4. /
  5. Object-Oriented Programming with S3 and R6 in R

Exercise

Overriding the Cooking Capabilities

Child classes can also extend functionality by overriding methods. They do this by defining methods with the same name as that of the parent.

Child classes can access public methods from their parent class by prefixing the name with super$.

Instructions

100 XP

A microwave oven has been predefined in your workspace.

  • Update the definition of the fancy microwave oven class to include a public element.
  • Override the cook() method.
    • The cook method should still take a time_seconds argument.
    • It should pass the time_seconds argument to the parent class' cook() method, …
    • then display an additional message() stating "Enjoy your dinner!".
  • Instantiate a fancy microwave oven object and assign it to a_fancy_microwave.
  • Call the cook() method for one second.