Menu
Topics Index
...
`

Equals


If you need explanation Read this topic

If you need Answer Take test on this topic

Equals
What will be the output of the following program?
public class PabloPicasso {
    public static void main(String[] args) {
        String name = "Pablo Picasso";
        String nameObj = new String(name);
        System.out.println("name and nameObj are same " + (name == nameObj));
    }
}

A. name and nameObj are same false
B. name and nameObj are same true
C. Some other output
D. Compilation Error or Runtime Error
Topic: Java equals method vs == Operator

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Answer : A
the statement name==nameObj will return false as StringComparision in java cannot be done using " == " operator..IF it was name.equals(nameObj) then it would have returned true

Posted by Deepak Kumar Yadav    2014-05-21 03:50:17


Answer: A.. The statement name==nameObj checks for both string object values and the object references... Here though the values are same, the references are not same.. So the output will be "false"

Posted by Ramya Bonagiri    2014-05-21 03:59:36


Congratulations Ramya Bonagiri. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-05-22 05:45:03


© meritcampus 2019

All Rights Reserved.

Open In App