Menu
Question Index
...

What will be the output of the following program?

public class StringDemo {
    public static void main(String[] args) {
        String str1 = "Merit";
        String str2 = "Merit";
        String str3 = new String("Merit");
        if (str1 == str2) {
            System.out.println("str1 and str2 are equal");
        }
        if (str1 == str3) {
            System.out.println("str1 and str3 are equal");
        }
        if (str2 == str3) {
            System.out.println("str2 and str3 are equal");
        }
    }
}


str1 and str2 are equal
str1 and str3 are equal
str2 and str3 are equal
str2 and str3 are equal
str1 and str2 are equal
Compilation Error or Runtime Error

Doubts

Problems

Topic: Literals 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