adplus-dvertising
frame-decoration

Question

What is the output of below code snippet?
public class Test 
{
 public static void main(String[] args) 
        {
  Set s = new HashSet();
  s.add(new Long(10));
  s.add(new Integer(10));
  for(Object object : s)
                {
      System.out.println("test - "+object);
  }
 }
}

a.

Test – 10
Test – 10

b.

Test – 10

c.

Runtime Exception

d.

Compilation Failure

Posted under Java Programming

Answer: (a).Test – 10
Test – 10

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of below code snippet?

Similar Questions

Discover Related MCQs

Q. Set has contains(Object o) method.

Q. What is the difference between TreeSet and SortedSet?

Q. What happens if two threads simultaneously modify TreeSet?

Q. What is the unique feature of LinkedHashSet?

Q. Which of these standard collection classes implements a linked list data structure?

Q. Which of these classes implements Set interface?

Q. Which of these method is used to add an element to the start of a LinkedList object?

Q. Which of these method of HashSet class is used to add elements to its object?

Q. Which of these methods can be used to delete the last element in a LinkedList object?

Q. Which of this method is used to change an element in a LinkedList Object?

Q. Which of these object stores association between keys and values?

Q. Which of these classes provide implementation of map interface?

Q. Which of these method is used to remove all keys/values pair from the invoking map?

Q. Which of these method Map class is used to obtain an element in the map having specified key?

Q. Which of these methods can be used to obtain set of all keys in a map?

Q. Which of these method is used add an element and corresponding key to a map?

Q. Which of these class object can be used to form a dynamic array?

Q. Which of these are legacy classes?

Q. Which of these is the interface of legacy?

Q. What is the name of a data member of class Vector which is used to store a number of elements in the vector?