• Card 17 / 76: 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(); }

    Answer:
    C) int mostPoints = 100; int score = 87; if ( mostPoints = score ) { setWinner(); }

  • Keyboard Shortcuts

    Previous Card ← Previous Card Button
    Next Card → Next Card Button
    Flip Card Space-Bar
<< First < Previous Next > Last >>

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now
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.

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

My OCA Mock

Author:

Access: Public Instant Grading

Flash Cards plugin by Curtis Blackwell github.com/curtisblackwell/flash_cards
Google Play and the Google Play logo are trademarks of Google Inc.
Ask
Briana Knowlton
Start Quiz
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>