Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a public class named Car.
Java
public class [1] { // class body }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
2fill in blank
mediumComplete the code to declare a public method named start inside the Car class.
Java
public class Car { public [1] start() { return "Car started"; } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
3fill in blank
hardFix the error in the code by completing the access modifier for the variable speed.
Java
public class Car { [1] int speed; public void setSpeed(int s) { speed = s; } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
4fill in blank
hardFill both blanks to create a public constructor for the Car class that sets the speed.
Java
public class Car { int speed; public [1]([2] int speed) { this.speed = speed; } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
5fill in blank
hardFill all three blanks to create a public method named accelerate that increases speed by a given amount and returns the new speed.
Java
public class Car { int speed; public int [1](int [2]) { speed [3] amount; return speed; } }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
