Java认证模考试题(三)
Question: 14
Which one of the following arguments is the correct argument of the main() method?
A. char args[]
B. char args[][]
C. String arg[]
D. String args
Explanation:
The argument of the main() method is an array of String. Then only answer C is an array of String.
Correct Answer: C 14 of 60
Question: 15
Which one of the following is correct to create an array?
A. float f[][] = new float[6][6];
B. float []f[] = new float[6][6];
C. float f[][] = new float[][6];
D. float [][]f = new float[6][6];
E. float [][]f = new float[6][];
Explanation:
In Java the declaration format allows the square brackets to be at the left or right of the variable name. But the new float[][6] is illegal.
Correct Answer: A,B,D,E 15 of 60
Question: 16
Given the following expression: int m[] = {0, 1, 2, 3, 4, 5, 6 };
Which result of the following expressions equals to the number of the array elements?
A. m.length()
B. m.length
C. m.length()+1
D. m.length+1
Explanation:
The number of elements in an array is stored in the length attribute in the array object.
Correct Answer: B 16 of 60
Question: 17
Given the following command to run a correct class: java MyTest a b c
Which statements are true?
A. args[0] = MyTest a b c
B. args[0] = MyTest
C. args[0] = a
D. args[1]= 'b'
Explanation:
The three arguments a b c are stored in the args[] array of the main() method. Then args[0]= a, args[1]= b, args[2]= c.
Correct Answer: C 17 of 60
Question: 18
Given the following code:
public class Test{
long a[] = new long[10];
public static void main ( String arg[] ) {
System.out.println ( a[6] );
}
}
Which statement is true?
A. Output is null.
B. Output is 0.
C. When compile, some error will occur.
D. When running, some error will occur.
Explanation:
When an array is created the members of the array is initialized. In this case all the elements are initialized to be 0.
Correct Answer: B 18 of 60
uestion: 19
Given the following fragment of code:
boolean m = true;
if ( m = false )
System.out.println(False);
else
System.out.println(True);
What is the result of the execution?
A. False
B. True
C. None
D. An error will occur when running.
Explanation:
= is the assignment operator. == is the compare operator. In this question the value of false is assigned to the variable m.
Correct Answer: A 19 of 60
Question: 20
Given the following code:
public class Test{
public static void main(String arg[]){
int i = 5;
do {
System.out.println(i);
} while (--i>5)
System.out.println(“finished”);
}
}
What will be output after execution?
A. 5
B. 4
C. 6
D. Finished
E. None
Explanation:
The expressions in the block of do/while loop will be executed at least once. If the condition of this loop is not met the loop will stop after once execution, otherwise, it will continue to loop until the condition is no met.
Correct Answer: A,D 20 of 60