1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Object-Oriented Programming in Java

Connected

Exercise

Overloading methods

A central aspect of Polymorphism is overloading, which allows object instances created from your classes to exist in different forms. You will implement a second way to drive to enable the Tesla to drive backward. This is a case of method overloading, where we want a functionality to possess different forms within the same class.

Instructions

100 XP
  • Create a second public void method, drive that takes a boolean parameter isDrivingBackward.
  • Inside the new drive method, print the message "driving backward".
  • Call the second drive method using the myTesla object instance with the parameter value true.