Question 16 / 90:  Which of the following code segments contain invalid Java statements? It can be assumed that all variables have been properly declared and initialized.

(Choose all that apply.)

A  int x = getSize();
B  int a = 1; int b = 2; int c = a = b;
C  int mostPoints = 100; int score = 87; if ( mostPoints = score ) { setWinner(); }
D  boolean stillRunning = true; if ( stillRunning = true ) { run(); }
<< First < Previous Flashcard Next > Last >>
Explanation:

C. This statement is not valid. The variable mostPoints is an int. It cannot be placed in an if statement without a relational operator. Remember that the assignment of primitive literals evaluate to primitive values.

A, B, and D are incorrect.

A is incorrect because the statement is valid—it is a simple assignment.

B is incorrect because the code segment is valid. It is legal to have more than one variable assigned on a line as seen in the last line of B. The last line of this segment sets a equal to b, and then c equal to a.

D is incorrect because the segment is valid. Because stillRunning is a boolean value, a relational operator is not needed. Note that while this answer is legal and compiles, it may not be what was intended, as relational operators are typically used in if statements.

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

My OCA Mock

Author:

Access: Public Instant Grading

Ask
Jesenia Wofford
Start Quiz
David Bourgeois
Start Quiz
Michael Sag
Start Exam
Keyaira Braxton
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>