A

Admin • 828.03K Points
Coach

Q. What will be the output of the following code –

Code:
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
public class CopyOnWriteArraySetTest
{
public static void main (String args[])
{
Set<String> copyOnWriteArraySet = new CopyOnWriteArraySet<String>();
copyOnWriteArraySet.add(” a “);
copyOnWriteArraySet.add ( ” b” );
Iterator<String> iterator = copyOnWriteArraySet.iterator();
while(iterator.hasNext())
{
copyOnWriteArraySet.add( ” c ” );
System.out.println(iterator.next());
}
}
}
  • (A) a followed by exception
  • (B) a
  • (C) a b
  • (D) Compile time exception
  • Correct Answer - Option(C)
  • Views: 11
  • Filed under category Java
  • Hashtags:

No solution found for this question.
Add Solution and get +2 points.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.