1Z0-803 · Question #68
Given a code fragment: What is the result?
The correct answer is D. Nothing is printed to the screen. 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 class do
Question
Given a code fragment:
What is the result?
Exhibit
Options
- AThey match
- BThey really match
- CThey match
- DNothing is printed to the screen
How the community answered
(60 responses)- A13% (8)
- B3% (2)
- C7% (4)
- D77% (46)
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 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, then a.equals(b) is the
Topics
Community Discussion
No community discussion yet for this question.
