Java程序员认证模拟题及详细分析(3)

4/7/2006来源:Java认证人气:10177

续:java程序员认证模拟题及分析(1) 和(2)
   51. Which correctly create an array of five empty Strings?
   A. String a[] = new String[5];
   for (int i=0;i<5;a[i++]=””);
   B. String a []={“”,””,””,””,””};
   C. String a[5];
   D. String [5] a;
   E. String [] a = new String[5];
   for (int i = 0 ;i<5;a[i++] = null);

   52. Which cannot be added to a Container?
   A. an Applet
   B. a Component
   C. a Container
   D. a MenuComponent
   E. a panel

   53. Which is the return value of Event listener?s method?
   A. String B. AWTEvent C. void D. int

   54. If we implements MouseListener, which is corrected argument of its method? (short answer)

   55. Use the Operator “>>” and “>>>”. Which statement is true?
   A. 1010 0000 0000 0000 0000 0000 0000 0000 >> 4 give
   0000 1010 0000 0000 0000 0000 0000 0000
   B. 1010 0000 0000 0000 0000 0000 0000 0000 >> 4 give
   1111 1010 0000 0000 0000 0000 0000 0000
   C. 1010 0000 0000 0000 0000 0000 0000 0000 >>> 4 give
   0000 1010 0000 0000 0000 0000 0000 0000
   D. 1010 0000 0000 0000 0000 0000 0000 0000 >>> 4 give
   1111 1010 0000 0000 0000 0000 0000 0000

   56. Give following fragment.
   Outer: for(int i=0; i<3; i++)
   inner:for(int j=0;j<3;j++){
   If(j>1)break outer;
   System.out.PRintln(j+”and”+i);
   }
   Which will be output?
   A. 0 and 0 B. 0 and 1 C. 0 and 2 D. 0 and 3
   E. 1 and 0 F. 1 and 1 G. 1 and 2 H. 1 and 3
   I. 2 and 0 J. 2 and 1 K. 2 and 2 L. 2 and 3

   57. Examine the following code which includes an inner class:
   public final class Test4 implements A{
   class Inner{
   void test(){
   if (Test4.this.flag);{
   sample();
   }
   }
   private boolean flag=false;
   }
   public void sample(){
   System.out.println(“Sample”);
   }
   public Test4(){
   (new Inner()).test();
   }
   public static void main(String args[]){
   new Test4();
   }
   }
   What is the result:
   A.Print out “Sample”
   B.Program produces no output but termiantes correctly.
   C. Program does not terminate.
   D.The program will not compile

   58. What is written to the standard output given the following statement:
   System.out.println(4|7);
   Select the right answer:
   A.4
   B.5
   C.6
   D.7
   E.0

   59. Look the inheritance relation:
   person
|
----------------
| |
man woman
   In a source of java have the following line:
   person p=new man();
   What statement are corrected?
   A. The expression is illegal.
   B. Compile corrected but running wrong.
   C. The expression is legal.
   D. Will construct a person?s object.
   60. Look the inheritance relation:
   person
|
----------------
| |
man woman
   In a source of java have the following line:
   woman w=new man():

   What statement are corrected?
   A. The expression is illegal.
   B. Compile corrected but running wrong.
   C. The expression is legal.
   D. Will construct a woman object.

   61. Which can NOT be used in declaring or declaring and initializing an automatic (method local) variable?
   A. final
   B. static
   C. expressions
   D. Constants of non-primitive type
   E. initialized arrays (such as “ {“Hello”,”Good bye”}”).

   62. Given the following incomplete method:
   1) public void method(){
   2)
   3) if (someTestFails()){
   4)
   5) }
   6)
   7) }
   You want to make this method throw an IOException if,and only if,the method someTestFails() returns a value of true.
   Which changes achieve this?
   A. Add at line 2:IOException e;
   B. Add at line 4:throw e;
   C. Add at line 4:throw new IOException();
   D. Add at line 6:throw new IOException();
   E. Modify the method declaration to indicate that an object of type Exception might be thrown.
   63. Given the following definition:
   String s = null;
   Which code fragments cause an object of type NullPointerException to be thrown?
   A. if((s!=null)&(s.length()>0))
   B. if((s!=null)&&(s.length()>0))
   C. if((s==null)|(s.length()==0))
   D. if((s==null)||(s.length()==0))

   64. The following is a program
   1) class Exsuper{
   2) String name;
   3) String nick_name;
   4)
   5) public ExSuper(String s,String t){
   6) name = s;
   7) nick_name = t;
   8) }
   9)
   10) public string toString(){
   11) return name;
   12) }
   13) }
   14)
   15) public class Example extends ExSuper{
   16)
   17) public Example(String s,String t){
   18) super(s,t);
   19) }
   20)
   21) public String to String(){
   22) return name +”a.k.a”+nick_name;
   23) }
   24)
   25) public static void main(String args[]){
   26) ExSuper a = new ExSuper(“First”,”1st”);
   27) ExSuper b = new Example(“Second”,”2nd”);
   28)
   29) System.out.println(“a is”+a.toString());
   30) System.out.println(“b is”+b.toString());
   31) }
   32) }
   What happens when the user attempts to compile and run this program?
   A. A Compiler error occurs at line 21
   B. An object of type ClassCastException is thrown at line 27
   C.The following output:
   a is First
   b is second
   D. The following output:
   a is First
   b is Secong a.k.a 2nd
   F. The following output:
   a is First a.k.a 1st
   b is Second a.k.a 2nd

   65. Which statements are true about Listeners?
   A. At most one listener can be added to any simple Component.
   B. The return value from a listener is used to control the invocation of other listener
   C. If multiple listeners are added to a single component, they must all be made friends to each other
   D. If multiple listeners are added to single component, the order of invocation of the listener is not specified.
   E. In the AWT, listener methods generally take an argument, which is an instance of some subclass of java.awt.AWTEvent class.

答案及详细分析:
51。A、B
注意,每个对象变量在未初始化前都为“null”,并不为“空”。当为“空”时,它已经被分配具体内存空间了,与“null”有本质的区别。
52。D
菜单控件只能添加到叫做菜单容器的特殊对象中,而且布局管理器对菜单控件不起任何作用。
53。C
事件监听器方法就是句柄方法,所有句柄方法的访问权限都是public,返回值类型都是void。
54。MouseEvent
此题是考试中常见的题型。一般来说,句柄方法的参数类型与监听器类型是匹配的,只有监听器MouseMotionListener的句柄方法的参数类型是MouseEvent,与相应监听器类型名称不匹配。
55。B、C
“>>” 是带符号右移,高位是“1”则补“1”,否则补“0”;“>>>”是无符号右移,又叫补零右移,不论高位是什么,都是补“0”。
56。A、E
注意标号的使用。另外,break表示跳出本语句块的执行,continue继续本块的执行。
57。A
回答此题时,要仔细阅读程序,注意到语句“if(Test4.this.flag);”有一分号,这是没有执行语句的条件语句,所以“sample()”方法总是被调用。
58。D
“|”是按位或运算符,先将4和7转为二进制数。转换后就是计算“100|111”,所以得到结果是“111”,转为十进制整形数是7。此题提醒考生注意,要熟悉各种运算符号的含义。
59。C
这是多态性的定义方式,p是父类引用指向子类对象。此时,编译器认为p是一个person,而不是man ,所以p只能实现父类的功能。但是当p调用被覆盖方法时,是指向子类中的该方法。
60.A
多态性的定义允许父类引用指向子类对象,但是不允许两个平等的子类有这样的操作。所以该表达式是不合法的。
61.B
自动变量前不能用“static”修饰。
以下定义都是允许的:
final Date d = new Date();
String [] s = {“Hello”,”abc”};
int i = x+4;
所以只有B选项是正确。
62.C、E
所有自定义异常,在方法体中抛出了,就必须在方法声明中抛出。所以除了C选项外,E也必须入选。
63.A、C
逻辑运算符“&&”、“||”,在运算中有“短路”行为:例如 A&&B,如果A的值为false,则直接将整个表达式的值置为false,对B的值不加考察。而运算符“&”、“|”就没有这种行为。所以在选项A、C中,“s.length()”会导致抛出空指针异常。
64.D
源程序的第27行,是多态性的定义。对象b调用被覆盖方法时是调用子类中的该方法。
65.D、E
一个控件可以注册多个监听器,并且事件的响应没有特定的顺序。句柄方法的参数是类AWTEvent类的子类。