Q: The statement used to find the total number of Strings present in the string array String s[] is:
-
A
s.length
-
B
s.length()
-
C
length(s)
-
D
len(s)
A
Answer:
A
Explanation:
Let's carefully analyze:
We have a string array String s[]. We want the number of elements in the array.
-
(a) s.length → ✅ Correct. For arrays in Java, .length without parentheses gives the number of elements.
-
(b) s.length() → ❌ Incorrect. length() is used for String objects, not arrays.
-
(c) length(s) → ❌ Not valid in Java.
-
(d) len(s) → ❌ Python syntax, not Java.
Answer: (a) s.length
Related Topic:
Share Above MCQ