Complete the code to create an object of the class Car.
Car myCar = new [1]();To create an object, use the class name with the new keyword. Class names in Java start with uppercase letters.
Complete the code to call the method startEngine on the car object.
myCar.[1]();To call a method, use the object name followed by a dot and the method name exactly as defined.
Fix the error in the code to access the speed attribute of the car object.
int currentSpeed = myCar.[1];Attributes are accessed by their exact name with correct case. Here, the attribute is 'speed' with lowercase 's'.
Fill both blanks to create a new Engine object and assign it to the car's engine attribute.
myCar.engine = new [1](); [2] engine = myCar.engine;
The class name for the engine is 'Engine'. We create a new Engine object and assign it to the car's engine attribute. Then we declare a variable of type Engine to refer to it.
Fill all three blanks to define a method in the Car class that returns the engine's horsepower.
public int [1]() { return this.engine.[2]; } Car myCar = new Car(); int hp = myCar.[3]();
The method name is 'getHorsepower'. It returns the 'horsepower' attribute of the engine. We call the method on the car object to get the horsepower value.