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(ws1.equals(hs) && ws2.equals(s1));
        System.out.print(ws2.equals(hs) && ws1.equals(s1));
    }
}


false
false
true
false
true
true
Compilation Error
Runtime Error

Doubts

Problems

Topic: Java Collection Algorithms

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App