Bird
0
0

What will be the output of this code snippet?

medium📝 Predict Output Q5 of 15
Java - Arrays
What will be the output of this code snippet?
String[] fruits = {"Apple", "Banana", "Cherry"};
System.out.println(fruits.length);
A2
BCompilation error
C0
D3
Step-by-Step Solution
Solution:
  1. Step 1: Understand array initialization and length property

    The array 'fruits' is initialized with 3 elements: "Apple", "Banana", "Cherry".
  2. Step 2: Check the length property

    The length property returns the number of elements in the array, which is 3.
  3. Final Answer:

    3 -> Option D
  4. Quick Check:

    Array length property = number of elements [OK]
Quick Trick: Use .length to get array size in Java [OK]
Common Mistakes:
  • Confusing length with last index (length - 1)
  • Trying to call length() method instead of property

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes