Topics Index

Boolean operators

If you need explanation Read this topic

If you need Answer Take test on this topic

Boolean operators
What will be the output of the following method with various values of a and b?
public void output(boolean a, boolean b) {
    if (a) {
    } else if (a && b) {
        System.out.println("A && B");
    } else {
        if (!b) {
        } else {

A. If a is true and b is true, then the output is "A && B"
B. If a is true and b is false, then the output is "notB"
C. If a is false and b is true, then the output is "ELSE"
D. If a is false and b is false, then the output is "ELSE"
Topic: if else if ladder 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.

option c.. as when a is false nd b is true....!b will be false nd else will be printed

Posted by Rasagna Veeramallu    2013-04-15 12:56:27

option C

Posted by Nikhitha Reddy    2013-04-15 12:56:54

the first if n else if fails bcoz a is false..and then inside else the first if fails bcoz (~true=false) and hence goes to inner else and prints ELSE

Posted by Nikhitha Reddy    2013-04-15 12:58:02

Anneerrudh Mmahepate :haha.. :D

Posted by Nikhitha Reddy    2013-04-15 12:59:13

answer is C...coz when a is true others if is satisfied..and does not enterr teh else case of C option....a is fals then goes to else goes to b is true so ELSE

Posted by Sravanthi Kappuram    2013-04-15 13:00:06

Congratulations Rasagna Veeramallu. You are today's daily dose winner. Please send us your mobile number and operator details in a private message. We will process it along with additional bonus for the new likes after we post tomorrow's daily dose.

Posted by Merit Campus    2013-04-15 15:13:01

thank u MC!! recieved rc

Posted by Rasagna Veeramallu    2013-04-17 14:23:04

© meritcampus 2019

All Rights Reserved.

Open In App