Exam 1z0-808 All QuestionsBrowse all questions from this exam
Question 10

Given the code fragment:

What is the result?

    Correct Answer: A

    The code first converts the StringBuilder object 'sb' to a String using the toString() method and then compares it with the String 's' using the equals() method. Since both 'sb.toString()' and 's' have the value 'Java', the equals() method returns true, and 'Match 1' is printed.

Discussion
Ankit1010Option: A

sb.toString() => converts it into String. and thereafter, using equals() method on String will do the value comparison. So, answer is A since the values are equal.

iheb07Option: A

Answer A

AhmadTechieOption: A

Answer is A. As sb.toString() => new string object gets created and String equals() method do content check

arjunrawatirissoftwareOption: A

Answer- A

SezamOption: A

The answer is A

willokansOption: D

Inconvertible type error between String "Java" and StringBuilder "Java". To resolve StringBuilder to String append .toString() method to sb

Def8Option: A

It is very simple since equals method compare by value.

ZINGOMOption: A

A tostring convert a StringBuffer to a string