Bird
0
0

Which of the following is a valid way to declare an array and get its length in Java?

easy📝 Syntax Q3 of 15
Java - Arrays
Which of the following is a valid way to declare an array and get its length in Java?
Aint[] arr = new int[5]; int len = arr.length;
Bint arr[] = new int(5); int len = arr.length();
Cint arr[] = new int[5]; int len = arr.size();
Dint arr = new int[5]; int len = arr.length;
Step-by-Step Solution
Solution:
  1. Step 1: Check array declaration syntax

    Correct array declaration uses square brackets and new int[5] to allocate size.
  2. Step 2: Check length access syntax

    Length is accessed as a property without parentheses: arr.length.
  3. Final Answer:

    int[] arr = new int[5]; int len = arr.length; -> Option A
  4. Quick Check:

    Array declared with [] and length accessed as property [OK]
Quick Trick: Declare arrays with [] and use .length property [OK]
Common Mistakes:
  • Using parentheses in new int(5)
  • Calling length() as a method
  • Using size() method on arrays
  • Declaring array without []

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes