JAVA題庫:格林模擬試題二(上)(4)

question 10)you want to find out the value of the last element of an array. you write the following code. what will happen when you compile and run it.?

public class myar{
public static void main(string argv[]){
int[] i = new int[5];
system.out.println(i[5]);
}
}
1) an error at compile time
2) an error at run time
3) the value 0 will be output
4) the string "null" will be output

question 11)you want to loop through an array and stop when you come to the last element. being a good java programmer and forgetting everything you ever knew about c/c++ you know that arrays contain information about their size. which of the following can you use?

1)myarray.length();
2)myarray.length;
3)myarray.size
4)myarray.size();

question 12)what best describes the appearance of an application with the following code?

import java.awt.*;
public class flowap extends frame{
public static void main(string argv[]){
  flowap fa=new flowap();
  fa.setsize(400,300);
  fa.setvisible(true);

}

flowap(){
  add(new button("one"));
  add(new button("two"));
  add(new button("three"));
  add(new button("four"));
  }//end of constructor



}//end of application

1) a frame with buttons marked one to four placed on each edge.
2) a frame with buutons marked one to four running from the top to bottom
3) a frame with one large button marked four in the centre
4) an error at run time indicating you have not set a layoutmanager