Top

Language Fundamentals - General Questions

1.

The == operator can be used to compare two String objects. The result is always true if the two strings are identical.

Answer: B

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?

Enter details here

2.

Objects of a subclass can be assigned to a super class reference.

Answer: A

Objects of a super class may not be assigned to a sub class reference. Food for thought: why is it so?

Enter details here

3.

Objects of a super class can always be assigned to a subclass reference.

Answer: B

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?

Enter details here

4.

An individual array element from an array of type int, when passed to a method is passed by value.

Answer: A

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

Enter details here

5.

An array in the Java programming language has the ability to store many different types of values.

Answer: B

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.

Enter details here

6.

Variables declared inside a for loop are limited in scope to the loop.

Answer: B

Any variable declared within a block statement such as a for or if cannot be referenced outside the block.

Enter details here

7.

For the [removed]y >= z && a == b) to be true, at least one of (y >= z) and (a == b) must be true.

Answer: B

For the result of a "&&" operation to be true, both operands must be true.

Enter details here

8.

break statement must always be present in the default case of a "switch" selection structure.

Answer: B

The break statement, which brings the computation out of the "switch" selection structure, is not required for the defalut case.

Enter details here

9.

The "switch" selection structure must end with the default case.

Answer: B

The default case in a switch structure is optional and only used when none of the other cases match.

Enter details here

10.

The [removed]y >= z && a == b) is evaluated by first evaluating the expression y >= z, and then evaluating a == b.

Answer: B

If y >= z is false, then there is no need to evaluate the second expression.

Enter details here

Loading…