Challenge - 5 Problems
Static Methods Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 code output
intermediate2:00remaining
Output of static method call
What is the output of the following Java program?
Java
public class Test { static int count = 0; public static void increment() { count++; } public static void main(String[] args) { increment(); increment(); System.out.println(count); } }
Attempts:
2 left
🧠 conceptual
intermediate1:30remaining
Static method access to instance variables
Which statement about static methods in Java is true?
Attempts:
2 left
🔧 debug
advanced2:00remaining
Identify the error in static method usage
What error will this code produce?
Java
public class Example { int number = 5; public static void printNumber() { System.out.println(number); } public static void main(String[] args) { printNumber(); } }
Attempts:
2 left
💻 code output
advanced1:30remaining
Output of static method with parameters
What is the output of this Java program?
Java
public class Calculator { public static int multiply(int a, int b) { return a * b; } public static void main(String[] args) { int result = multiply(3, 4); System.out.println(result); } }
Attempts:
2 left
🚀 application
expert2:30remaining
Static method call from instance method
Consider this Java class. What will be the output when main runs?
Java
public class Counter { private static int count = 0; public void increment() { count++; } public static void printCount() { System.out.println(count); } public static void main(String[] args) { Counter c1 = new Counter(); Counter c2 = new Counter(); c1.increment(); c2.increment(); printCount(); } }
Attempts:
2 left
