0
0
Javaprogramming~15 mins

Heap memory in Java - Interactive Code Practice

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

Complete the code to create an object stored in heap memory.

Java
String str = new [1]("Hello");
🎯 Drag options to blanks, or click blank then click option
Aboolean
Bint
Cchar
DString
Attempts:
3 left
2fill in blank
medium

Complete the code to assign a new object reference to the variable.

Java
MyClass obj = [1] MyClass();
🎯 Drag options to blanks, or click blank then click option
Amake
Bnew
Ccreate
Dinit
Attempts:
3 left
3fill in blank
hard

Fix the error in the code to properly create an array in heap memory.

Java
int[] numbers = new int[1]5;
🎯 Drag options to blanks, or click blank then click option
A{}
B()
C[]
D< >
Attempts:
3 left
4fill in blank
hard

Fill both blanks to create a new object and call its method.

Java
MyObject obj = [1] MyObject();
obj.[2]();
🎯 Drag options to blanks, or click blank then click option
Anew
Bstart
Crun
Dcreate
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to create a HashMap, add a key-value pair, and retrieve a value.

Java
HashMap<String, Integer> map = [1] HashMap<>();
map.[2]("age", 30);
int age = map.[3]("age");
🎯 Drag options to blanks, or click blank then click option
Anew
Bput
Cget
Dadd
Attempts:
3 left