Bird
0
0

What will be printed by the following Java code?

medium📝 Predict Output Q4 of 15
Java - Arrays
What will be printed by the following Java code?
char[] letters = {'a', 'b', 'c', 'd'};
System.out.println(letters.length);
A0
B3
C4
DError
Step-by-Step Solution
Solution:
  1. Step 1: Check array initialization

    The array letters has 4 elements: 'a', 'b', 'c', 'd'.
  2. Step 2: Access length property

    letters.length returns the number of elements, which is 4.
  3. Final Answer:

    4 -> Option C
  4. Quick Check:

    Array length counts elements, so output is 4. [OK]
Quick Trick: Array length equals number of elements. [OK]
Common Mistakes:
  • Confusing length with last index
  • Expecting length as a method
  • Miscounting elements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes