Given:
2. import java.util.*; 3. public class Main { 4. public static void main(String[] args) { 5. Set s1 = new HashSet(); 6. s1.add(0); /*from w w w . ja v a2s .com*/ 7. s1.add("1"); 8. doShape(s1); 9. } 10. static void doShape(Set<Number> s) { 11. do2(s); 12. Iterator i = s.iterator(); 13. while(i.hasNext()) System.out.print(i.next() + " "); 14. Object[] oa = s.toArray(); 15. for(int x = 0; x < oa.length; x++) 16. System.out.print(oa[x] + " "); 17. System.out.println(s.contains(1)); 18. } 19. static void do2(Set s2) { System.out.print(s2.size() + " "); } 20. }
What is the most likely result?
B is correct.
Set s1 (which contains a String and an Integer) can be iterated over, copied to an Object[], sized, and searched.
A is incorrect because s1 doesn't contain an Integer with a value of 1.
C, D, E, F, and G are incorrect because the code is all legal and runs without exception.