Menu
Question Index
...

What will the output of the following program?

class StringTest {

    public static void main(String[] args) {
        String a = "A";
        String b = "B";
        String ab = a + b;
        String a1 = new String("A");
        String a2 = new String(a);
        System.out.print(ab.equals(a + b) ? ":" : ";");
        System.out.print(ab == a + b ? "(" : "-");
        System.out.print(a.equals(a1) ? ")" : "D");
        System.out.print(a == a1 ? ":" : ";");
        System.out.print(a2 == a1 ? "-" : "!");
        System.out.print(a == b ? "P" : "D");
    }
}


:();!D
:();-D
:-);-D
:-);!D
None of the above

Doubts

Problems

Topic: Java equals method vs == Operator

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App