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

Connected

Exercise

Constructor overloading

We can overload the constructor with Polymorphism since it is like any other method. You will edit the Tesla class to have a second constructor, which takes a car's insurance status and allows you to create multiple object instances for the Tesla class using different constructors.

Instructions

100 XP
  • Complete the second constructor method for the Tesla class to take an extra boolean isInsured as a parameter.
  • Inside the new constructor method for the Tesla class, set the isInsured class properties to the corresponding constructor parameter.
  • Create the second object instance of the Tesla class, called mySecondTesla, using the new constructor method passing the parameters "modelY", "black", and false as values.