Question 25 / 90:  Given the following code segment testing the equality of two strings, what will be printed?
String string = "Dollar bill";

string.replace("Dollar bill", "Silver dollar");

if ("Dollar bill".equals(string)) {

System.out.println("I have a dollar bill.");

} else {

System.out.println("I have a silver dollar.");

}

A  I have a dollar bill.
B  have a silver dollar.
C  The code will not compile because of an error at line 2.
D  The code will not compile because of an error at line 3.
<< First < Previous Next > Last >>
Explanation:

A. Strings are immutable, so the statement at line 2 does not affect the string; it’s as if nothing

ever happened. Explicitly overwriting the value of the string object would have changed the

result: string = string.replace("Dollar bill", "Silver dollar");

B, C, and D are incorrect.

B is incorrect because the condition results in true.

C and D are incorrect because the code compiles fine.

Exam Home Page
https://www.jobilize.com/quiz-my-oca-mock-exam-by-mike-wolf

My OCA Mock

Author:

Access: Public Instant Grading

Ask
Eric Crawford
Start Quiz
Brooke Delaney
Start Exam
Copy and paste the following HTML code into your website or blog.
<iframe src="https://www.jobilize.com/embed/quiz-my-oca-mock-exam-by-mike-wolf" 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>