0
0
Javaprogramming~10 mins

Object lifecycle 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 a new object of class Car.

Java
Car myCar = new [1]();
Drag options to blanks, or click blank then click option'
AObject
Bcar
CCar
DVehicle
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using lowercase class name like 'car' causes errors.
Using unrelated class names like 'Vehicle' or 'Object'.
2fill in blank
medium

Complete the code to call the constructor of class Person with a name parameter.

Java
Person p = new Person([1]);
Drag options to blanks, or click blank then click option'
A"Alice"
B25
Ctrue
Dnull
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Passing a number instead of a string.
Forgetting quotes around the name.
3fill in blank
hard

Fix the error in the code to properly destroy an object reference.

Java
myObject = [1];
Drag options to blanks, or click blank then click option'
Adelete
Bnull
Cremove
Dvoid
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'delete' which is not valid in Java.
Using 'remove' or 'void' which are invalid here.
4fill in blank
hard

Fill both blanks to create an object and call its method.

Java
Car [1] = new [2]();
[1].startEngine();
Drag options to blanks, or click blank then click option'
AmyCar
BCar
Cengine
DVehicle
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using different names for variable and constructor.
Using invalid variable names.
5fill in blank
hard

Fill all three blanks to create a Person object, assign it to a variable, and call a method.

Java
Person [1] = new [2]([3]);
[1].sayHello();
Drag options to blanks, or click blank then click option'
Aperson1
BPerson
C"Bob"
Dgreet
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Mismatching variable and constructor names.
Passing a parameter without quotes.