String a=new String("A");String b=new String("A");String c="A";String d="A";Then which of the following returns true?1. if(a==b)2. if(b==c)3. if(c==d)4. if(d==a)

Questions by jhansisiripura

Showing Answers 1 - 5 of 5 Answers

DIBYENDU ROY

  • Aug 14th, 2006
 

The answer will be (c==d)..if equals() wud have been used the results wud be different

  Was this answer useful?  Yes

Mohd shadab

  • Aug 26th, 2006
 

String a=new String("A");

String b=new String("A");

a and b are two different object and when we are using "==" then we are checking that both the object are same or not.

String a; means we have created a reference variable i.e a  and it is referring a value and if two reference variable referring same then they are equal and that is why c==d istrue.

  Was this answer useful?  Yes

sammaiah nagapuri

  • Sep 6th, 2006
 

the if(c==d) gives the true only. the reason behind this is whenever you create the object by not using "new" operator like string a="A" then it will search whether is there any object with same content.if there is any same object then it simply assigns to previous existing object.but when you create the object with new then it will create new obj every time.thats all

  Was this answer useful?  Yes

Michael B

  • Sep 26th, 2006
 

The right answer is 'none of these "returns" a value'.I'm ASSUMING you're trying to say:Which of the following evaluate true?1. a==b2. b==c3. c==d4. d==a

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions