22. A Java array is an ordered collection of three kinds of things. What are they?
Fill in the blank.
正确答案:primitives. object references, references to other arrays.
20. There are seven characters, at least one of which must be included to indicate a floating point literal. What are they?
Fill in the blank.
正确答案:'E','e', 'F', 'f', 'D', 'd', '.'
18. Show six different ways to express the decimal value 28 as an integral(完整的) literal.(文字的,照字面上的)
Fill in the blank.
正确答案:28,034, 0x 1c , 0x 1C , 0X 1c , 0X 1C
4. How you can use the escape notation u to set the variable c, declared as a char, to the Unicode character whose value is hex 0X 30A 0?
Fill in the blank.
正确答案:C=/u 30a 0;
10.What output is produced by the following program?
class Test{
public static void main(String args[]){
long size=10;
int[]array=new int[size];
size=20;
System.out.println(array.length);
}
}
Select the one right answer.
A. A compiler error.
B. A runtime error.
C. 10
D. 20
正确答案:A
28. What output is produced by the following program? Note that the main() method is not declared public.
class Test{
static void main(String args[]){
System.out.println("OK");
}
}
Select the one right answer.
A. A compiler error.
B. A runtime error.
C. OK
正确答案: C
29. What output is produced by the following program? Note that the main() method is not declared static.
class Test{
public void main(String args[]){
System.out.println("OK");
}
}
Select the one right answer.
A. A compiler error.
B. A runtime error.
C. OK
正确答案: B
33. True or false? In Java primitives(原始的) are passed by value and objects are passed by reference.
Fill in the blank.
正确答案: False
30. What is the purpose of the reference to the array of String references in the argument list of the main() method?
Fill in the blank.
正确答案: Thansfer of command-line arguments
、
500. Examine the following code which includes an inner class:
public final class Test implements A{
class Inner{
void test(){
if (!Test.this.flag);{
sample();
}
}
private boolean flag = false;
}
publi void sample(){
System.out.println("Sample");
}
public Test(){
(new Inner()).test();
}
public static void main(String args[]){
new Test();
}
}
What is the result?
A. Print out "Sample"
B. Program produces no output but terminates correctly.
C. Program does not terminate.
D. The program will not compile
正确答案: A
511. What appears in the standard output if the method named problem() in the code below throws an instance of class Exception when the method named trythis() is invoked?
public void trythis(){
try{
System.out.println("1");
problem();
}catch(RuntimeException x){
System.out.println("2");
return;
}catch(Exception x){
System.out.println("3");
return;
}finally{
System.out.println("4");
}
System.out.println("5");
}
Select all valid answers.
A. "1"
B. "2"
C. "3"
D. "4"
E. "5"
正确答案: A、C、D
513. Analyze the following code.
void looper(){
int x=0;
one:
while(x<10){
two: 非法标号
System.out.println(++x);
if(x > 3)
break two;
}
}
Select all valid answer.
A. This code compiles
B. This code does not compile
C. This code writes the number 0 to the standard output
D. The numbers 1 and 2 to the standard outout
E. The numbers 3 and to the standard outout
F. The numbers 4 to the standard outout
G. The numbers 5 through 9 to the standard outout
H. The numbers 10 to the standard outout
正确答案: B
520.What code placed after the comment //For loop
would populate the elements of the array ia[] with values of the variable i?
public class Test{
public static void main(String argv[]){
Test 1=new Test();
1.amethod();
}
public void anethod(){
int ia[]=new int[4];
//Start For loop
{
ia[i]=i;
System.out.println(ia[i]);
}
}
}
Select the one right answer.
A. for(int i=0;i<ia.length()-1;i++)
B. for(int i=0;i<ia.length();i++)
C. for(int i=1;i<4.i++)
D. for(int i=0;i<ia.length;i++)
正确答案: D
523. What will happen when you attempt to compile and run the following code?
public class Test{
static public long i=10;
public static void main(String argv[]){
switch(i){
default:
System.out.println("no value given");
case 1:
System.out.println("one");
case 10:
System.out.println("ten");
case 5):
System.out.println("five");
}
}
}
Select the one right answer.
A. Compile time error
B. Output of "ten"followed by "five"
C. Output of "ten"
D. Compilation and run time error because of location of default
正确答案: A
525. The thread run() method has the following code, what is the result when the thread runs?
try{
sleep(200); 不会扔出一个IOException
System.out.println("Printing from thread run()method");
}catch(IOException ie){}
Selet the one right answer.
A. Compile time error
B. Prints on the console Printing from thread run() method
C. At line 2 the thread will be stop running and resumes after 200 milliseconds and prints Printing from thread run() method
D. At line 2 the thread will be stop running and resumes exactly 200 milliseconds elapsed
正确答案: A
534. Given the incompleted method:
//line 1
{
success = connect();
if (success==-1){
throw new TimedOutException();
}
}
TimedOutException is not a RuntimeException. Which can complete the method of declaration when added at line 1?
A. public void method()
B. public void method() throws Exception
C. public void method() throws TimedOutException
D. public void method() throw TimedOutException
E. public throw TimedOutException viod method()
正确答案: B、C
542. Given the following code:
class Test{
public static void main(String args[]){
System.out.println(hai());
}
static int hai(){
try{
return 1;
}
catch(Exception e){
System.out.println("Exception");
}
finally{
System.out.println("Finally");
Return 2;
}
}
}
What will be the out put?
A. Compilation Error void main Can't return any value.
B. Prints Exception.
C. Prints Exception Finally.
D. Prints Finally and 1.
E. Prints Finally and 2.
正确答案:E