21Which of the following assignment
is not correct?
A. float f = 11.1;
B. double d = 5.3E12;
C. double d = 3.14159;
D. double d = 3.14D.
22Given the uncompleted code of a class:
class Person {
String name, department;
int age;
public Person(String n){ name = n; }
public Person(String n, int a){ name = n; age = a; }
public Person(String n, String d, int a) {
// doing the same as two arguments version of constructor
// including assignment name=n,age=a
department = d;
}
}
Which expression can be added at the "doing the same as..."
part of the constructor?
A. Person(n,a);
B. this(Person(n,a));
C. this(n,a);
D. this(name,age).
23Which of the following statements about variables and their scopes
are true?
A. Instance variables are member variables of a class.
B. Instance variables are declared with the static keyword.
C. Local variables defined inside a method are created when the method
is executed.
D. Local variables must be initialized before they are used.
24public void test() {
try { oneMethod();
System.out.println("condition 1");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("condition 2");
} catch(Exception e) {
System.out.println("condition 3");
} finally {
System.out.println("finally");
}
}
Which will display if oneMethod run normally?
A. condition 1
B. condition 2
C. condition 3
D. finally
25Given the following code:
public class Test {
void printValue(int m){
do { System.out.println("The value is"+m);
}
while( --m > 10 )
}
public static void main(String arg[]) {
int i=10;
Test t= new Test();
t.printValue(i);
}
}
Which will be output?
A. The value is 8
B. The value is 9
C. The value is 10
D. The value is 11
26Which of the following statements about declaration are true?
A. Declaration of primitive types such as boolean, byte and so on
does not allocate memory space for the variable.
B. Declaration of primitive types such as boolean, byte and so on
allocates memory space for the variable.
C. Declaration of nonprimitive types such as String, Vector and so
on does not allocate memory space for the object.
D. Declaration of nonprimitive types such as String, Vector ans so
on allocates memory space for the object.
27In the Java API documentation which sections are included in a class
document?
A. The description of the class and its purpose
B. A list of methods in its super class
C. A list of member variable
D. The class hierarchy
28Given the following code:
1) public void modify() {
2) int i, j, k;
3) i = 100;
4) while ( i > 0 ) {
5) j = i * 2;
6) System.out.println (" The value of j is " + j );
7) k = k + 1;
8) i--;
9) }
10) }
Which line might cause an error during compilation?
A. line 4
B. line 6
C. line 7
D. line 8
29Which of the following statements about variables and scope are
true?
A. Local variables defined inside a method are destroyed when the
method is exited.
B. Local variables are also called automatic variables.
C. Variables defined outside a method are created when the object
is constructed.
D. A method parameter variable continues to exist for as long as the
object is needed in which the method is defined.
30A class design requires that a member variable cannot be accessible
directly outside the class. Which modifier should be used to obtain
the access control?
A. public
B. no modifier
C. protected
D. private
答案依次为:
(a),(c),(acd),(ad),(c),(cd),(acd),(c),(abc),(d)
|