技术开发 频道

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

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.
0
相关文章