-
What is the output of this program?
public class Result
{
public static void main(String args[])
{
Double num0 = new Double(260.0062);
Double num1 = new Double(260.0062123456);
try
{
int p = num1.compareTo(num0);
System.out.print(p);
}
catch(ClassCastException e)
{
System.out.print("Exception");
}
}
}
-
- Exception
- 0
- 1
- -1
- None of these
Correct Option: C
num1.compareTo() methods two double values, if they are equal then 0 is returned and if not equal then 1 is returned, here 260.0062 and 260.0062123456 are not equal hence 1 is returned and stored in p.