Syvum Home Page

Home > Quiz Games > Java Programming > Print Preview

Java Programming : Language Basics : True or False

Formats Info Page Worksheet / Test Paper Quiz Review

Hide all answers   View all answers   Print   Try the Quiz

Answer the following questions about basics of the Java programming language. These include concepts like operators, variables, declarations, basic language structures such as if, for, switch, etc.


1. The modulus operator (%) in Java can be used only with variables of integer type.
• True
• False
Answer: 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.

2. Declarations must appear at the start of the body of a Java method.
• True
• False
Answer: False
They can appear anywhere within the body of the method.

3. All bitwise operations are carried out with the same level of precedence in Java.
• True
• False
Answer: False
All operations in Java, including the bitwise operations, are carried out with a definite precedence.


4. The operations y >> 3 and y >>> 3 produce the same result when y > 0.
• True
• False
Answer: 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.

5. consider the statement "x = (a > b) ? a : b"; then the value of x is 27, if a = 18 and b = 27.
• True
• False
Answer: True
the statement is equivalent to: if (a > b) x = a; else x = b;

6. 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
Answer: 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.

7. The expression (y >= z && a == b) is evaluated by first evaluating the expression y >= z, and then evaluating a == b.
• True
• False
Answer: False
If y >= z is false, then there is no need to evaluate the second expression.

8. The "switch" selection structure must end with the default case.
• True
• False
Answer: False
The default case in a switch structure is optional and only used when none of the other cases match.

9. A break statement must always be present in the default case of a "switch" selection structure.
• True
• False
Answer: False
The break statement, which brings the computation out of the "switch" selection structure, is not required for the defalut case.

10. For the expression (y >= z && a == b) to be true, at least one of (y >= z) and (a == b) must be true.
• True
• False
Answer: False
For the result of a "&&" operation to be true, both operands must be true.

11. Variables declared inside a for loop are limited in scope to the loop.
• True
• False
Answer: False
Any variable declared within a block statement such as a for or if cannot be referenced outside the block.

12. An array in the Java programming language has the ability to store many different types of values.
• True
• False
Answer: 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.

13. An individual array element from an array of type int, when passed to a method is passed by value.
• True
• False
Answer: 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.

14. Objects of a super class can always be assigned to a subclass reference.
• True
• False
Answer: 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?

15. Objects of a subclass can be assigned to a super class reference.
• True
• False
Answer: True
Objects of a super class may not be assigned to a sub class reference. Food for thought: why is it so?

16. The == operator can be used to compare two String objects. The result is always true if the two strings are identical.
• True
• False
Answer: 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?

  Try the Quiz :     Java Programming : Classes : True or False


Contact Info © 1999-2024 Syvum Technologies Inc. Privacy Policy Disclaimer and Copyright
Previous
-
Next
-