Challenge - 5 Problems
Master of Method Parameters
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 code output
intermediate2:00remaining
Output of method with primitive parameter modification
What is the output of the following Java code?
Java
public class Test { public static void modify(int x) { x = x + 10; } public static void main(String[] args) { int a = 5; modify(a); System.out.println(a); } }
Attempts:
2 left
💻 code output
intermediate2:00remaining
Output of method with object parameter modification
What is the output of this Java program?
Java
class Box { int value; Box(int v) { value = v; } } public class Test { public static void modify(Box b) { b.value = 10; } public static void main(String[] args) { Box box = new Box(5); modify(box); System.out.println(box.value); } }
Attempts:
2 left
💻 code output
advanced2:00remaining
Output of method with varargs parameter
What will be printed when this Java code runs?
Java
public class Test { public static int sum(int... numbers) { int total = 0; for (int n : numbers) { total += n; } return total; } public static void main(String[] args) { System.out.println(sum(1, 2, 3)); } }
Attempts:
2 left
💻 code output
advanced2:00remaining
Output of method with overloaded parameters
What is the output of this Java program?
Java
public class Test { public static void print(int x) { System.out.println("int: " + x); } public static void print(String x) { System.out.println("String: " + x); } public static void main(String[] args) { print(5); print(null); } }
Attempts:
2 left
💻 code output
expert2:00remaining
Output of method with final parameter and reassignment attempt
What happens when this Java code runs?
Java
public class Test { public static void modify(final int x) { // x = x + 1; // Uncommenting this line causes what? System.out.println(x); } public static void main(String[] args) { modify(5); } }
Attempts:
2 left
