Menu
Question Index
...

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) {
        System.out.println("A");
    } else if (a && b) {
        System.out.println("A && B");
    } else {
        if (!b) {
            System.out.println("notB");
        } else {
            System.out.println("ELSE");
        }
    }
}


If a is true and b is true, then the output is "A && B"
If a is true and b is false, then the output is "notB"
If a is false and b is true, then the output is "ELSE"
If a is false and b is false, then the output is "ELSE"

Doubts

Problems

Topic: if else if ladder In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App