Question | Answer | Explanation |
The modulus operator (%) in Java can be used only with variables of integer type. True
False
| False | The modulus operator (%) may be used with floating-point as well as integer types. It returns the remainder of a division operation, e.g., 10 % 6 will return 4. |
Declarations must appear at the start of the body of a Java method. True
False
| False | They can appear anywhere within the body of the method. |
All bitwise operations are carried out with the same level of precedence in Java. True
False
| False | All operations in Java, including the bitwise operations, are carried out with a definite precedence. |
The operations y >> 3 and y >>> 3 produce the same result when y > 0. True False
| True | The shift operation "y1 >>> y2" is identical to "y1 >> y2" for all positive values of y1. It shifts the bits in y1 to the right by y2 positions. |
consider the statement "x = (a > b) ? a : b"; then the value of x is 27, if a = 18 and b = 27. True False
| True | the statement is equivalent to: if (a > b) x = a; else x = b; |
Whenever the "&&" operator is used, such as in: exp1 && exp2 where exp1 and exp2 are boolean expressions, both the boolean expressions are not always evaluated. True False
| True | If the first expression is false, the result of the "&&" operation will always be false regardless of the second expression. The "&" operator on the other hand forces the evaluation of the second expression even if the first expression is false. |
The expression (y >= z && a == b) is evaluated by first evaluating the expression y >= z, and then evaluating a == b. True
False
| False | If y >= z is false, then there is no need to evaluate the second expression. |
The "switch" selection structure must end with the default case. True
False
| False | The default case in a switch structure is optional and only used when none of the other cases match. |
A break statement must always be present in the default case of a "switch" selection structure. True
False
| False | The break statement, which brings the computation out of the "switch" selection structure, is not required for the defalut case. |
For the expression (y >= z && a == b) to be true, at least one of (y >= z) and (a == b) must be true. True
False
| False | For the result of a "&&" operation to be true, both operands must be true. |
Variables declared inside a for loop are limited in scope to the loop. True
False
| False | Any variable declared within a block statement such as a for or if cannot be referenced outside the block. |
An array in the Java programming language has the ability to store many different types of values. True
False
| False | All elements of an erray must be of the same type. However, it is possible to declare an array of objects, which may of instances of different classes. |
An individual array element from an array of type int, when passed to a method is passed by value. True False
| True | Individual elements of an array of this type are passed by value as a parameter to a method. Any changes to them in the method will not change the value of the array element. |
Objects of a super class can always be assigned to a subclass reference. True
False
| False | Objects of a subclass may be assigned to a super class reference. Food for thought: is there a loss in functionality when this is done? |
Objects of a subclass can be assigned to a super class reference. True False
| True | Objects of a super class may not be assigned to a sub class reference. Food for thought: why is it so? |
The == operator can be used to compare two String objects. The result is always true if the two strings are identical. True
False
| False | String objects must be compared using the "equals" method of one of the objects. Food for thought: will the == operator ever return true when two string objects are compared using it? |