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

Connected

Exercise

Creating a constructor for car class

It is important to be able to set values for a class’s properties to use them effectively. You will create a Constructor for the Car class and ensure that its properties are set to some values.

Remember: The constructor of a class will always be called when we create an instance.

Instructions

100 XP
  • Create a constructor method for the Car class that takes no parameters.
  • Inside the constructor, set the color property to be a String "red"
  • Inside the constructor, set the year to be an Integer 2019
  • Print out the color property of the myCar object instance.