Initializing Array Elements With Loops
An array books has been declared to store Book objects. Which of the following code segments correctly initializes each element of the books array with a new Book object?
I.
for (Book b : books)
b = new Book();
II.
for (int i = 0; i < books.length; i++)
books[i] = new Book();
III.
for (Book b : books)
books[b] = new Book();
A
III only
B
II only
C
I and II only
D
I, II, and III
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | ravi.palepu | 2 | 2 | 0m 42s | 158 |
| #2 | kaisuki | 1 | 2 | 0m 00s | 90 |
| #3 | singh.advik13 | 1 | 1 | 2m 07s | -27 |
| #4 | geethasailaja | 1 | 4 | 2m 06s | -56 |
| #5 | y.seong2027 | 2 | 3 | 4m 37s | -87 |
| #6 | singhris000 | 1 | 4 | 5m 24s | -254 |
APFIVE