Bird
0
0

What will be printed by this code?

medium📝 Predict Output Q5 of 15
Java - Arrays
What will be printed by this code?
int[] numbers = {10, 20, 30, 40};
System.out.println(numbers[2]);
A30
B40
C20
D10
Step-by-Step Solution
Solution:
  1. Step 1: Identify index used in array access

    Index 2 refers to the third element in the array (0-based indexing).
  2. Step 2: Find element at index 2

    Element at index 2 is 30.
  3. Final Answer:

    30 -> Option A
  4. Quick Check:

    Array index 2 value = 30 [OK]
Quick Trick: Array indices start at 0 in Java [OK]
Common Mistakes:
  • Confusing index 2 with 3rd element
  • Using 1-based indexing
  • Printing wrong element

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes