Bird
0
0

What will be printed when this code runs?

medium📝 Predict Output Q5 of 15
Java - Methods and Code Reusability
What will be printed when this code runs?
public class Test {
  public static void printNumber(int n) {
    System.out.println(n);
  }
  public static void main(String[] args) {
    printNumber(10);
  }
}
A10
Bn
CprintNumber
DCompilation error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze method call with argument

    The main method calls printNumber with 10 as argument.
  2. Step 2: Understand printNumber behavior

    printNumber prints the value of n, which is 10.
  3. Final Answer:

    10 -> Option A
  4. Quick Check:

    Method prints argument value [OK]
Quick Trick: Method prints the passed argument value [OK]
Common Mistakes:
  • Printing variable name instead of value
  • Confusing method name with output
  • Assuming error without syntax issues

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes