- 论坛徽章:
- 0
|
SCJP综合测试题
12. If you compile and execute an application with the following code in its main() method:
String s = new String( "Computer" );
if( s == "Computer" )
System.out.println( "Equal A" );
if( s.equals( "Computer" ) )
System.out.println( "Equal B" );
A. It will not compile because the String class does not support the = = operator.
B. It will compile and run, but nothing is printed.
C. "Equal A" is the only thing that is printed.
D. "Equal B" is the only thing that is printed.
E.Both "Equal A" and "Equal B" are printed.
13. Consider the two statements:
1. boolean passingScore = false && grade == 70;
2. boolean passingScore = false & grade == 70;
The expression
grade == 70
is evaluated:
A. in both 1 and 2
B. in neither 1 nor 2
C. in 1 but not 2
D. in 2 but not 1
E.invalid because false should be FALSE
14. Given the variable declarations below:
byte myByte;
int myInt;
long myLong;
char myChar;
float myFloat;
double myDouble;
Which one of the following assignments would need an explicit cast?
A. myInt = myByte;
B. myInt = myLong;
C. myByte = 3;
D. myInt = myChar;
E. myFloat = myDouble;
F. myFloat = 3;
G. myDouble = 3.0;
15. Consider this class example:
class MyPoint
{ void myMethod()
{ int x, y;
x = 5; y = 3;
System.out.print( " ( " + x + ", " + y + " ) " );
switchCoords( x, y );
System.out.print( " ( " + x + ", " + y + " ) " );
}
void switchCoords( int x, int y )
{ int temp;
temp = x;
x = y;
y = temp;
System.out.print( " ( " + x + ", " + y + " ) " );
}
}
What is printed to standard output if myMethod() is executed?
A. (5, 3) (5, 3) (5, 3)
B. (5, 3) (3, 5) (3, 5)
C. (5, 3) (3, 5) (5, 3)
16. To declare an array of 31 floating point numbers representing snowfall for each day of March in Gnome, Alaska, which declarations would be valid?
A. double snow[] = new double[31];
B. double snow[31] = new array[31];
C. double snow[31] = new array;
D. double[] snow = new double[31];
17. If arr[] contains only positive integer values, what does this function do?
public int guessWhat( int arr[] )
{ int x= 0;
for( int i = 0; i < arr.length; i++ )
x = x < arr ? arr : x;
return x;
}
A. Returns the index of the highest element in the array
B. Returns true/false if there are any elements that repeat in the array
C. Returns how many even numbers are in the array
D. Returns the highest element in the array
E. Returns the number of question marks in the array
18. Consider the code below:
arr[0] = new int[4];
arr[1] = new int[3];
arr[2] = new int[2];
arr[3] = new int[1];
for( int n = 0; n < 4; n++ )
System.out.println( /* what goes here? */ );
Which statement below, when inserted as the body of the for loop, would print the number of values in each row?
A. arr[n].length();
B. arr.size;
C. arr.size -1;
D. arr[n][size];
E. arr[n].length;
19.If size = 4, triArray looks like:
int[][] makeArray( int size)
{ int[][] triArray = new int[size] [];
int val=1;
for( int i = 0; i < triArray.length; i++ )
{ triArray = new int[i+1];
for( int j=0; j < triArray.length; j++ )
{ triArray[j] = val++;
}
}
return triArray;
}
A.
1 2 3 4
5 6 7
8 9
10
B. 1 4 9 16
C. 1 2 3 4
D.
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
E.
1
2 3
4 5 6
7 8 9 10
20. Which of the following are legal declarations of a two-dimensional array of integers?
A. int[5][5]a = new int[][];
B. int a = new int[5,5];
C. int[]a[] = new int[5][5];
D. int[][]a = new[5]int[5];
21. Which of the following are correct methods for initializing the array "dayhigh" with 7 values?
A. int dayhigh = { 24, 23, 24, 25, 25, 23, 21 };
B.int dayhigh[] = { 24, 23, 24, 25, 25, 23, 21 };
C. int[] dayhigh = { 24, 23, 24, 25, 25, 23, 21 };
D. int dayhigh [] = new int[24, 23, 24, 25, 25, 23, 21];
E. int dayhigh = new[24, 23, 24, 25, 25, 23, 21];
22. Choose all valid forms of the argument list for the FileOutputStream constructor shown below:
A. FileOutputStream( FileDescriptor fd )
B. FileOutputStream( String n, boolean a )
C. FileOutputStream( boolean a )
D. FileOutputStream()
E. FileOutputStream( File f ) |
|