Challenge - 5 Problems
Master of Method Calling
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 code output
intermediate2:00remaining
Output of method call with recursion
What is the output of this Java program when the
printNumbers method is called with argument 3?Java
public class Test { public static void printNumbers(int n) { if (n == 0) return; System.out.print(n + " "); printNumbers(n - 1); } public static void main(String[] args) { printNumbers(3); } }
Attempts:
2 left
💻 code output
intermediate2:00remaining
Output of method call with overloaded methods
What is the output of this Java program?
Java
public class OverloadTest { public static void display(int a) { System.out.println("int: " + a); } public static void display(String a) { System.out.println("String: " + a); } public static void main(String[] args) { display(5); display("hello"); } }
Attempts:
2 left
🔧 debug
advanced2:00remaining
Identify the error in method call
What error does this Java code produce when compiled?
Java
public class ErrorTest { public static void greet() { System.out.println("Hello"); } public static void main(String[] args) { greet("World"); } }
Attempts:
2 left
💻 code output
advanced2:00remaining
Output of method call with static and instance methods
What is the output of this Java program?
Java
public class StaticInstance { public static void staticMethod() { System.out.println("Static method called"); } public void instanceMethod() { System.out.println("Instance method called"); } public static void main(String[] args) { StaticInstance.staticMethod(); StaticInstance obj = new StaticInstance(); obj.instanceMethod(); } }
Attempts:
2 left
💻 code output
expert3:00remaining
Output of method call with method overriding and polymorphism
What is the output of this Java program?
Java
class Parent { void show() { System.out.println("Parent show"); } } class Child extends Parent { @Override void show() { System.out.println("Child show"); } } public class TestPolymorphism { public static void main(String[] args) { Parent obj = new Child(); obj.show(); } }
Attempts:
2 left
