Home Tutorial Java Scjp Part9 SCJP Module-9 Question-18

 
 

SCJP Module-9 Question-18
Posted on: July 17, 2010 at 12:00 AM
The Sample program given below will test your understanding about the HashSet class of collection framework in Java.

Given below the sample code :

1.  import java.util.*;
2.  public class MyString {
3.  private String a;
4.  public MyString(String a) { this.a = a; }
5.  public static void main(String[] args) {
6.  HashSet<Object> hash = new HashSet<Object>();
7.  MyString ms1 = new MyString("Roseindia");
8.  MyString ms2 = new MyString("Roseindia");
9.  String a1 = new String("Roseindia");
10. String a2 = new String("Roseindia");
11. hash.add(ms1); hash.add(ms2); hash.add(a1); hash.add(a2);
12. System.out.println(hash.size()); } }

What will be the output of the above code ?

1. 0

2. 1

3. 2

4. 3

Answer

(4)

Related Tags for SCJP Module-9 Question-18:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.