Menu
Topics Index
...
`

Select


If you need explanation Read this topic

If you need Answer Take test on this topic

Select
What will be the output of the following program?
public class Compare {
    public static void main(String[] args) {
        Boolean pen = true;
        Boolean pencil = false;
        System.out.println(!pen.booleanValue());
        System.out.println(Boolean.compare(pen, pencil));
        System.out.println(pencil.compareTo(pen));
    }
}

A. false
1
-1
B. false
-1
1
C. Compilation Error
D. Runtime Error
Topic: Java Boolean Class

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.

option C as Boolean class has no compare method

Posted by Sasikanth Sharma    2014-06-27 13:02:09


A

Posted by Akash Subbu    2014-06-27 13:26:50


ans A as pen and pencil are boolean virables with true and false and ! true is false and prints and compare gives 1 and compareTo gives -1 as both are not equal

Posted by Siva Yelchuri    2014-06-27 13:32:46


B

Posted by Rathod Ajay    2014-06-27 13:43:39


A

Posted by Shashi Kumar    2014-06-27 17:58:55


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

Posted by Merit Campus    2014-06-30 05:15:11


© meritcampus 2019

All Rights Reserved.

Open In App