Menu
Topics Index
...
`

Lamp is2615


If you need explanation Read this topic

If you need Answer Take test on this topic

Lamp is2615
What will be the output of the following program?
public class Switch {
    public static void main(String[] args) {
        boolean lampX = false, result;
        boolean lampY = true;
        result = lampY || lampX;
        System.out.println("Lamp switch-on " + result);
        result = lampY | lampX;
        System.out.println("Lamp switch-on " + result);
    }
}

A. Lamp switch-on true
Lamp switch-on false
B. Lamp switch-on true
Lamp switch-on true
C. Lamp switch-on false
Lamp switch-on true
D. Compilation Error or Runtime Error
Topic: Short Circuit Logical Operators 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.

answer is B.
there is no difference whether it is | or ||.
it will give true.

Posted by Gopinath Manchikanti    2014-02-06 12:44:44


Answer is B... in the given question,when || is used only lampY is evaluated bcoz lampy is true....when | is used both lampY and lampX are evaluated....result of  both the evaluations of | and || is true...thus the ans is B

Posted by Sneha Rapool    2014-02-06 13:00:36


answer is b......|| indicates or operator so true or false is true .......| is bitwise or so true | false is true...so answer is B :-)

Posted by Anvesh Athmakuri    2014-02-06 13:45:49


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

Posted by Merit Campus    2014-02-07 09:06:31


© meritcampus 2019

All Rights Reserved.

Open In App