Menu
Topics Index
...
`

Collections1670


If you need explanation Read this topic

If you need Answer Take test on this topic

Collections1670
What will be the output of the following program?
import java.util.*;
public class GuessTheOutput {
    public static void main(String args[]) {
        Set<GuessTheOutput> set = new TreeSet<GuessTheOutput>();
        set.add(new GuessTheOutput());//LINE A
        set.add(new GuessTheOutput());//LINE B
        set.add(new GuessTheOutput());
        System.out.println(set);
    }
}

A. Some output will print
B. Compile and runs successfully but output will not produce
C. Compilation successfully but Runtime Error will occurs
D. Compilation Error
Topic: Java TreeSet - TreeSet Examples in Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

C.is the answer.bcz.invalid casting is being taken place.

Posted by Shabaaz Shaikz    2014-04-23 13:31:04


Ans is c programs compiles successfully and exception occurs ie run time error as GuessTheOutput cannot be cast to java.lang.comparable at Treeset.add

Posted by Bharath Yelchuri    2014-04-23 13:34:08


ans c: casting of guesstheoutput is not valid

Posted by Manasa Jyothi Sree    2014-04-23 13:37:00


Ans is c

Posted by Akhil Goutham Kotini    2014-04-23 14:02:03


Congratulations Shabaaz Shaikz. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-04-24 04:19:27


Thanq MC.

Posted by Shabaaz Shaikz    2014-04-24 11:56:42


© meritcampus 2019

All Rights Reserved.

Open In App