0
0
Javaprogramming~10 mins

Object interaction 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 create an object of the class Car.

Java
Car myCar = new [1]();
Drag options to blanks, or click blank then click option'
ACar
BObject
CVehicle
Dcar
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using lowercase class name like 'car' instead of 'Car'.
Using a different class name like 'Vehicle' which is not defined.
2fill in blank
medium

Complete the code to call the method startEngine on the car object.

Java
myCar.[1]();
Drag options to blanks, or click blank then click option'
AbeginEngine
BrunEngine
CengineStart
DstartEngine
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using incorrect method names like 'runEngine' or 'engineStart'.
Forgetting the parentheses after the method name.
3fill in blank
hard

Fix the error in the code to access the speed attribute of the car object.

Java
int currentSpeed = myCar.[1];
Drag options to blanks, or click blank then click option'
Aspeed
BcurrentSpeed
CgetSpeed()
DSpeed
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using uppercase 'Speed' instead of 'speed'.
Trying to call an attribute as a method like 'getSpeed()' if it does not exist.
4fill in blank
hard

Fill both blanks to create a new Engine object and assign it to the car's engine attribute.

Java
myCar.engine = new [1]();
[2] engine = myCar.engine;
Drag options to blanks, or click blank then click option'
AEngine
BCar
DVehicle
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'Car' or 'Vehicle' instead of 'Engine' for the object type.
Mismatching the variable type and the object assigned.
5fill in blank
hard

Fill all three blanks to define a method in the Car class that returns the engine's horsepower.

Java
public int [1]() {
    return this.engine.[2];
}

Car myCar = new Car();
int hp = myCar.[3]();
Drag options to blanks, or click blank then click option'
AgetHorsepower
Bhorsepower
DstartEngine
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using wrong method names like 'startEngine' instead of 'getHorsepower'.
Using incorrect attribute names.