Question 20 / 90:  What is the output for the following Java code segment? The text in parentheses is meant to describe the whitespace and is not part of the output.
String fiveSpaces = "     ";

String SCJA = "SCJA";

String lineToDisplay = "fiveSpaces + SCJA + fiveSpaces";

System.out.println(lineToDisplay.trim());

A  SCJA (no trailing and leading spaces)
B  SCJA (five leading and trailing spaces)
C  SCJA (four leading and trailing spaces)
D  fiveSpaces + SCJA + fiveSpaces
<< First < Previous Next > Last >>
Explanation:

D. This is a trick question. Notice the quotation marks used to initialize the lineToDisplay variable.

The quotation marks indicate that everything between them is passed as a string. This is not concatenating the variables, as it might seem at first.

The trim method removes whitespace from the beginning and end of a string.

The string is everything between the quotation marks. Since the string neither starts nor ends with spaces, nothing is trimmed.

A, B, and C are incorrect.

If the quotation marks were not present, A would have been correct.

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

My OCA Mock

Author:

Access: Public Instant Grading

Ask
Edgar Delgado
Start Test
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>