MCQs
Total Questions : 42
| Page 5 of 5 pages
Answer: Option D. -> There is a syntax error on line 6.
Using the integer 1 in the while statement, or any other looping or conditional
construct for that matter, will result in a compiler error. This is old C Program
syntax, not valid Java.
A, B and C are incorrect because line 1 is valid (Java is case sensitive so While
is a valid class name). Line 8 is also valid because an equation may be placed
in a String operation as shown.
Answer: Option A. -> 1 and 3
Switch statements are based on integer expressions and since both bytes and
chars can implicitly be widened to an integer, these can also be used. Also shorts
can be used. Short and Long are wrapper classes and reference types can not
be used as variables.