Java程序员认证模拟题及详细分析(3)
来源:优易学  2010-1-15 9:38:33   【优易学:中国教育考试门户网】   资料下载   IT书店

 

   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类的子类。

上一页  [1] [2] [3] 

责任编辑:cyth

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训