Loading

Q1.

The Enhanced For Loop in Java is also known as:

A. Advanced For Loop
B. for-each Loop

C. Lambda Loop

D. Iterator Loop

Q2.

Which of the following is the correct syntax for an Enhanced For Loop?

A. for (int i = 0; i < arr.length; i++)

B. for (int num : arr)

C. foreach (int num in arr)

D. for (arr : int num)

Q3.

What will be the output of the following code?


int[] nums = {1, 2, 3};

for (int n : nums) {

    System.out.print(n + " ");

}

A. 123
B. 1 2 3
C. 3 2 1
D. Compilation error

Q4.

Which of the following is a limitation of the Enhanced For Loop?

A. It cannot be used with arrays.

B. It does not allow index access.

C. It throws IndexOutOfBoundsException by default.

D. It cannot iterate collections.

Q5.

Can we use the Enhanced For Loop to remove elements from a collection?

A. Yes, always
B. No, it will cause ConcurrentModificationException

C. Yes, but only for arrays

D. Yes, but only in Java 8 and later