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

 
 

SCJP Module-9 Question-18
Posted on: July 17, 2010 at 12:00 AM
Advertisement
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)

Advertisement

Related Tags for SCJP Module-9 Question-18:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 17, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com