java test2
TRANSCRIPT
Java Test 2 date: 13/7/2011
Name:______________________________________
Q1: Which of the following statements about arrays are true?A. An array is a group of variables containing values that all have the same type.B. Elements are located by index or subscript.C. The length of an array c is determined by the expression c.length();.D. The zeroth element of array c is specified by c[ 0 ].
a. A, C, D.b. A, B, D.c. C, D.d. A, B, C, D.
Q2: Method calls cannot be distinguished by ________.a. method name.b. return type.c. parameter lists.d. method signature.
Q3: Which of the following for-loop control headers results in equivalent numbers of iterations:
A. for ( int q = 1; q <= 100; q++ )B. for ( int q = 100; q >= 0; q-- )C. for ( int q = 99; q > 0; q -= 9 ) D. for ( int q = 990; q > 0; q -= 90 )
a. A and B.b. C and D.c. A and B have equivalent iterations and C and D have
equivalent iterations.d. None of the loops have equivalent iterations.
Q4: A well-designed methoda. performs multiple unrelated tasks.b. repeats code found in other methods.c. contains thousands of lines of code.d. performs a single, well-defined task.
Q5: Any field declared with keyword ________ is constant.a. static.b. const.c. constant.d. final.
Q6: A static method can ________.a. call only other static methods of the same class directly.b. manipulate only static fields in the same class directly.c. be called using the class name and a dot (.).d. All of the above.
Q7: Overloaded methods always have the same _________.a. method name.b. return type.c. number of parameters.d. order of the parameters.
Q8: Which of the following methods are overloaded with respect to one another?
public int max ( int a, int b ) { … }public double max ( double a, double b ) { … }public int max ( int a, int b, int c ) { … }public double max ( double a, double b, double c ) { … }
a. A and B are overloaded; C and D are overloaded.b. A and C are overloaded; B and D are overloaded.c. A, B and C are overloaded.d. All these four methods are overloaded.
Q9: Attempting to access an array element out of the bounds of an array, causes a(n) .a. ArrayOutOfBoundsException.b. ArrayElementOutOfBoundsException.c. ArrayIndexOutOfBoundsException.d. ArrayException.
Q10: A constructor cannot:a. be overloaded.b. initialize variables to their defaults.c. specify return types or return values.d. have the same name as the class.
Q11: A package is:a. A directory structure used to organize classes and
interfaces.b. A mechanism for software reuse.c. A group of related classes and interfaces.d. All of the above.
Q12: Overriding a method differs from overloading a method because:a. Overloaded methods have the same signature.b. Overridden methods have the same signature.c. Both of the above. d. Neither of the above.
Q13: A(n) class cannot be instantiated.a. final.b. concrete.c. abstract.d. polymorphic.
Q14: Declaring a method final means:a. it will prepare the object for garbage collection.b. it cannot be accessed from outside its class.c. it cannot be overloaded.d. it cannot be overridden.