PASS - TAKER : Anonymous

Java SE 8 - OCA Operators

Correct : 10

100% Complete (success)

100 %

False : 0

0% Complete (success)

0 %

Anonymous 2018-11-06T19:06:46


1. Given: {code} What is the result?

This is a ternary nested in a ternary. Both ternary expressions are false.


2. Given: {code} What is the result?

The == operator tests for reference variable equality, not object equality.


3. Given: {code} And the command-line invocation: java Fork live2 What is the result?

Because the short-circuit (||) is not used, both operands are evaluated. Since args[1] is past the args array bounds, an ArrayIndexOutOfBoundsException is thrown.


4. Given: {code} What is the result?

Concatenation runs from left to right, and if either operand is a String, the operands are concatenated. If both operands are numbers, they are added together.


6. Given: {code} What is the result? (Choose all that apply.)

When dividing ints, remainders are always rounded down.


7. Given: {code} What is the result?

All this syntax is correct. The for-each iterates through the enum using the values() method to return an array. An enum can be compared using either equals() or ==. An enum can be used in a ternary operator’s boolean test.


8. Given: {code} Which are true? (Choose all that apply.)

Line 9 uses the modulus operator, which returns the remainder of the division, which in this case is 1. Also, line 9 sets b2 to false, and it doesn’t test b2’s value. Line 10 would set b2 to true; however, the short-circuit operator keeps the expression b2 = true from being executed.


9. Given: {code} Which two are true about the value of mask and the value of count at line 10? (Choose two.)

At line 7 the || keeps count from being incremented, but the | allows mask to be incremented. At line 8 the ^ returns true only if exactly one operand is true. At line 9 mask is 2 and the && keeps count from being incremented.


10. Given: {code} What is the result?

First, remember that instanceof can look up through multiple levels of an inheritance tree. Also remember that instanceof is commonly used before attempting a downcast; so in this case, after line 15, it would be possible to say Speedboat s3 = (Speedboat)b2;.


11. Given: {code} What is the result?

Stage 1: resolve any use of unary operators Stage 2: resolve any use of multiplication-related operators Stage 3: handle addition and subtraction Stage 4: handle any relationship operators Stage 5: deal with the equality operators Stage 6: deal with the logical operators Stage 7: do the short-circuit operators Stage 8: finally, do the assignment operators