0
0
Javaprogramming~10 mins

Why object-oriented programming is used in Java - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a class named Car.

Java
public class [1] {}
Drag options to blanks, or click blank then click option'
AObject
Bcar
CCar
DVehicle
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using lowercase for class names
Using unrelated names
2fill in blank
medium

Complete the code to create an object of class Car.

Java
Car myCar = new [1]();
Drag options to blanks, or click blank then click option'
ACar
BVehicle
Ccar
DObject
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using lowercase class names
Using wrong class names
3fill in blank
hard

Fix the error in the method to return the car's speed.

Java
public int getSpeed() {
    return [1];
}
Drag options to blanks, or click blank then click option'
Aspeed
Bthis.speed
CSpeed
DgetSpeed
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using method name instead of variable
Wrong case for variable name
4fill in blank
hard

Fill both blanks to define a constructor that sets the car's speed.

Java
public [1](int [2]) {
    this.speed = speed;
}
Drag options to blanks, or click blank then click option'
ACar
Bspeed
CCarSpeed
Dvalue
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Constructor name different from class
Parameter name mismatch
5fill in blank
hard

Fill all three blanks to create a method that increases the car's speed by a given amount.

Java
public void [1](int [2]) {
    this.speed [3] amount;
}
Drag options to blanks, or click blank then click option'
Aaccelerate
Bamount
C+=
DspeedUp
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using wrong method name
Using '=' instead of '+='
Parameter name mismatch