Given a code fragment: What is the result?
A.
They match They real match
B.
They really match
C.
They match
D.
Nothing is printed to the screen
Given a code fragment: What is the result?
A.
They match They real match
B.
They really match
C.
They match
D.
Nothing is printed to the screen
B
B. I tested it in eclipse.
Check tom’s comment here:
http://www.aiotestking.com/oracle/what-is-the-result-299/
Answer: B
its choice D.
Explanation/Reference:
Explanation: Strings can not be compared with the usual <, , or >= operators, and the == and != operators
don’t compare the characters in the strings. So the first if statement fails.
Equals works fine on strings. But it does not work here.The second if-statement also fails. The StringBuffer
class does not override the equals method so it uses the equals method of Object. If a and b are two objects
from a class which doesn’t override equals, thena.equals(b) is the same as a == b