Menu
Topics Index
...
`

Duster


If you need explanation Read this topic

If you need Answer Take test on this topic

Duster
What will be the output of the following program?
public class Car {
    public static void main(String[] args) {
        String name = new String("Renault Duster");
        String reference = "Renault Duster";
        System.out.println(name + " and " + reference + " are same " + name.equals(reference));
        System.out.println(name + " and " + reference + " are same " + (name == reference));
    }
}

A. Renault Duster and Renault Duster are same true
Renault Duster and Renault Duster are same true
B. Renault Duster and Renault Duster are same true
Renault Duster and Renault Duster are same false
C. Renault Duster and Duster are same false
Renault Duster and Duster are same false
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.

Ans:B  in strings equals method compares content hence "true". "==" compares references hence "false"

Posted by Indrasena Reddy    2014-02-10 03:28:55


answer is  A because both strings are equal.

Posted by Shiva Goud    2014-02-10 04:28:04


Ans is B ,,String overrides the equals method so it checks for content comparision so .equals() is "true" ,where as == compares references both are in different one is created in StringConstantPool and another one in Heap so it is "False".

Posted by Nagendra Reddy    2014-02-10 06:06:10


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

Posted by Merit Campus    2014-02-11 03:42:08


© meritcampus 2019

All Rights Reserved.

Open In App