Challenge - 5 Problems
Java Memory Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 code output
intermediate2:00remaining
Output of primitive and reference variable changes
What is the output of the following Java code?
Java
public class Test { public static void main(String[] args) { int a = 5; int b = a; b = 10; System.out.println("a = " + a); System.out.println("b = " + b); } }
Attempts:
2 left
💻 code output
intermediate2:00remaining
Output when modifying an object reference
What is the output of this Java code?
Java
public class Test { public static void main(String[] args) { int[] arr1 = {1, 2, 3}; int[] arr2 = arr1; arr2[0] = 10; System.out.println(arr1[0]); } }
Attempts:
2 left
💻 code output
advanced2:00remaining
Effect of reassigning object references
What is the output of this Java code?
Java
public class Test { public static void main(String[] args) { StringBuilder sb1 = new StringBuilder("Hello"); StringBuilder sb2 = sb1; sb2.append(" World"); sb2 = new StringBuilder("New"); System.out.println(sb1.toString()); } }
Attempts:
2 left
💻 code output
advanced2:00remaining
Output when passing primitives and objects to methods
What is the output of this Java code?
Java
public class Test { public static void main(String[] args) { int x = 5; StringBuilder sb = new StringBuilder("Hi"); modify(x, sb); System.out.println(x + " " + sb.toString()); } static void modify(int a, StringBuilder b) { a = 10; b.append(" there"); } }
Attempts:
2 left
🧠 conceptual
expert2:00remaining
Understanding memory behavior of primitives and references
Which statement best describes how Java stores primitive types and reference types in memory?
Attempts:
2 left
