Question 22 / 297:  Which of the statements will evaluate to true?
public class Tester {

public static void main(String[] args) {

StringBuffer sb1 = new StringBuffer("javachamp");

StringBuffer sb2 = new StringBuffer("javachamp");

boolean stmt1 =sb1.equals(sb2) ;

boolean stmt2 = sb1 == sb2;

String s1 = new String("javachamp");

String s2 = new String("javachamp");

boolean stmt3 = s1.equals(s2);

boolean stmt4 = s1 == s2;

}

}

A  stmt1
B  stmt2
C  stmt3
D  stmt4
<< First < Previous Next > Last >>
Explanation:

String overrides equals(object) while StringBuffer doesn't

Exam Home Page
Ask
Joanna Smithback
Start Quiz
Copy and paste the following HTML code into your website or blog.
<iframe src="https://www.jobilize.com/embed/java-certification-questions" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>