Menu
Question Index
...

What will be the output of the following program?

public class EqualOperators2
{
    public static void main(String args[])
    {
        String str2 = "MyName";
        String str3 = str2;
        if (str2 == str3)
        {
            System.out.println("Objects are equal");
        }
        else
        {
            System.out.println("Objects are not equal");
        }
        if (str3.equals(str2))
        {
            System.out.println("Objects are equal");
        }
        else
        {
            System.out.println("Objects are not equal");
        }
    }
}


Objects are not equal
Objects are equal
Objects are equal
Objects are equal
Objects are not equal
Objects are not equal
Objects are equal
Objects are not equal
Compilation Error or Runtime Error

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