Menu
Question Index
...

What will be the output of the following program?

public class Mystery {
    public static void main(String[] args) {
        char a = 'B';
        char b = 'A';
        char c = 'B';
        char d = 'A';
        String hear = "bad";
        String song = "good";
        String good = "hear";
        print(hear, song, a, b, c);
        print(good, hear, (char) (b + c), (char) (a + c), 'A');
        print(good, hear, (char) (a + b), a, c);
    }
    public static void print(String d, String e, char a, char b, char c) {
        System.out.println("-" + e + "-" + a + "-" + b + "-" + c + "-" + d);
    }
}


-good-B-A-B-bad
-bad-?-?-A-hear
-bad-A-B-B-hear
-good-B-A-B-bad
-bad-A-B-A-hear
-bad-A-B-B-hear
-good-B-A-B-bad
-bad-B-B-A-hear
-bad-A-B-B-hear
Some other output
Output can not be determined
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Methods - Parameter Passing And Scope

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App