Complete the code to declare a public class named Car.
public class [1] { // class body }
The class name must match the identifier after the public class keywords. Here, Car is the correct class name.
Complete the code to declare a public method named start inside the Car class.
public class Car { public [1] start() { return "Car started"; } }
void when the method returns a value.int.The method start returns a string, so its return type must be String.
Fix the error in the code by completing the access modifier for the variable speed.
public class Car { [1] int speed; public void setSpeed(int s) { speed = s; } }
The variable speed is accessed inside the class and should be private to encapsulate the data and allow controlled access through methods.
Fill both blanks to create a public constructor for the Car class that sets the speed.
public class Car { int speed; public [1]([2] int speed) { this.speed = speed; } }
void as constructor name.The constructor name must match the class name Car, and the parameter type is int for speed.
Fill all three blanks to create a public method named accelerate that increases speed by a given amount and returns the new speed.
public class Car { int speed; public int [1](int [2]) { speed [3] amount; return speed; } }
The method name is accelerate, the parameter is amount, and the speed is increased using +=.
