Menu
Question Index
...

What will be the output of following program?

import java.util.*;
public class Names {
    static String s;
    public Names(String s) {
        Names.s = s;
    }
    public static void main(String[] args) {
        HashSet<Object> hs = new HashSet<Object>();
        Names ws1 = new Names("pranavi");
        Names ws2 = new Names("madhavi");
        String s1 = new String("jahnavi");
        String s2 = new String("vyshnavi");
        String s3 = new String("vyshnavi");
        hs.add(ws1);
        hs.add(ws2);
        hs.add(s1);
        hs.add(s2);
        hs.add(s3);
        System.out.println(hs.size());
    }
}


3
4
7
Some other output
Compilation Error or Runtimr Error.

Doubts

Problems

Topic: HashSet Class In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App