0
0
Javaprogramming~10 mins

Real-world modeling in Java - Interactive Code Practice

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'
AEngine
BDrive
CCar
DVehicle
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using a name that does not represent the object, like Engine or Drive.
2fill in blank
medium

Complete the code to add a field for the car's color.

Java
public class Car {
    private [1] color;
}
Drag options to blanks, or click blank then click option'
Aint
Bboolean
Cdouble
DString
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using numeric types like int or double for color.
3fill in blank
hard

Fix the error in the constructor to set the car's color.

Java
public class Car {
    private String color;

    public Car(String [1]) {
        this.color = color;
    }
}
Drag options to blanks, or click blank then click option'
Acolor
Bpaint
Cshade
Dhue
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using a different parameter name than the one assigned to the field.
4fill in blank
hard

Fill both blanks to add a method that returns the car's color.

Java
public class Car {
    private String color;

    public String [1]() {
        return [2];
    }
}
Drag options to blanks, or click blank then click option'
AgetColor
Bcolor
Cthis.color
DfetchColor
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Returning the parameter name or a wrong variable.
Using a method name that does not follow the getter naming convention.
5fill in blank
hard

Fill all three blanks to add a method that sets the car's color.

Java
public class Car {
    private String color;

    public void [1](String [2]) {
        this.[3] = [2];
    }
}
Drag options to blanks, or click blank then click option'
AsetColor
BnewColor
Ccolor
DupdateColor
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using the same name for parameter and field without 'this.' prefix.
Using incorrect method or parameter names.