Complete the code to define a class named "Car".
public [1] Car { // class body }
The keyword class is used to define a class in Java.
Complete the code to declare a private integer field named "speed" inside the class.
public class Car { [1] int speed; }
The keyword private restricts access to the field within the class only.
Fix the error in the constructor definition to properly initialize the "speed" field.
public class Car { private int speed; public Car(int [1]) { speed = [1]; } }
The constructor parameter should have a different name than the field to avoid confusion. Here, value is used, and then assigned to the field speed.
Fill both blanks to create a method named "getSpeed" that returns the speed.
public class Car { private int speed; public [1] [2]() { return speed; } }
The method getSpeed returns an integer value, so its return type is int.
Fill all three blanks to create a setter method named "setSpeed" that sets the speed field.
public class Car { private int speed; public [1] [2]([3] newSpeed) { speed = newSpeed; } }
The setter method setSpeed does not return a value, so its return type is void. It takes an int parameter named newSpeed.