QUESTION 51
Given the exhibit:
Which two statements are true? (choose two)
A. Certkiller.beta ( ) is a valid invocation of beta ( )
B. Certkiller.alpha ( ) is a valid invocation of alpha ( )
C. method beta ( ) can directly call method alpha ( )
D. method alpha ( ) can directly call method beta ( )
Answer: ( B, C )
alpha()是静态方法,可以使用Certkiller.alpha()直接调用。
non-static方法可以直接调用static或者non-static方法
参考大纲:面向对象
QUESTION 52
Given the exhibit:
Which two classes use the Shape class correctly? ( choose two)
A. public class Circle implements Shape {
private int radius;
}
B. public abstract class Circle extends Shape {
private int radius;
}
C. public class Circle extends Shape {
private int radius;
public void draw ( );
}
D. public abstract class Circle implements Shape {
private int radius;
public void draw ( );
}
E. public class Circle extends Shape {
private int radius;
public void draw () { /*CODE HERE */}
}
F. public abstract class Circle implements Shape {
private int radius;
public void draw ( ) { /* code here */ }
}
Answer: ( B, E )
抽象类是被继承的,抽象方法是要被改写的,如果某个类继承了一个抽象类而没有实现父类中的抽象方法,那么这个子类也应该定义为抽象的
A 错误 覆写抽象类应该使用extends
C 错误 覆写Shape时 必须实现抽象方法draw(),或者把Circle定义成abstract类。
D 错误 覆写抽象类应该使用extends
F 错误 覆写抽象类应该使用extends
参考大纲:面向对象
QUESTION 53
Given the exhibit:
What is the result ?
A. B
B. The code exception is thrown at runtime
C. The cod run with no output.
D. Compilation fails because of an error in line 12.
E. Compilation fails because of an error in line 15.
F. Compilation fails because of an error in line 16.
Answer: ( F )
第16行做编译时类型识别,此时会把a当作A类型的对象去调用process( )方法,因此必须在代码中显示处理process()方法可能抛出的异常。但是最后执行时做运行时类型识别,会将a作为B类型去调用process()方法,此时不抛出异常,会打印出“B”。
参考大纲:面向对象和异常处理
QUESTION 54
Given the exhibit:
What is the result if NullPointerException occurs on line 34?
A. c
B. a
C. ab
D. ac
E. bc
F. abc
Answer: ( D )
参考大纲:异常处理
QUESTION 55
Given the exhibit:
Which exception or error will be thrown when a programmer attempts to run this code?
A. java.lang.StackOverflowError
B. java.lang.IllegalStateException
C. java.lang.ExceptionInInitializerError
D. java.lang.ArrayIndexOutOfBoundsException
Answer: ( C )
编译成功,运行时报错。因为第11行没有给int[ ] 设置空间。如果a = null; 则12行抛空指针。
参考大纲:语言基础 和 面向对象 — static块
QUESTION 56
Exhibit:
Which two statements are true if a NullPointerException is thrown on line 3 of
class C? (choose two)
A. The application will crash.
B. The code on line 29 will be executed
C. The code on line 5 of class A will execute.
D. The code on line 5 of class B will execute.
E. The exception will be propagated back to line 27.
Answer: ( B, E )
参考大纲:异常处理
QUESTION 57
Given the exhibit:
What is the result?
A. 0
B. 10
C. 12
D. Line 29 will never be reached.
Answer: ( C )
参考大纲:流程控制
QUESTION 58
Given the exhibit:
A. The value "4" is printed at the command line
B. Compilation fails because of an error in line 5.
C. Compilation fails because of an error in line 9.
D. A NullPointerException occurs at runtime.
E. A NumberFormatException occurs at runtime.
F. An IllegalStateException occurs at runtime.
Answer: ( D )
第二行“Integer I”,I 现在是对象,没有赋值,默认是null,所以将会产生空指针异常
参考大纲:面向对象 — 成员变量默认值
QUESTION 59
Given the exhibit:
What is the result?
A. 3, 2, 1,
B. 1, 2, 3,
C. Compilation fails
D. The code runs with no output
E. An exception is thrown at runtime
Answer: ( C )
For/in语句不支持Iterator类 第八行会出现错误
参考大纲:流程控制
QUESTION 60
Given the exhibit:
11. public void testIfA(){
12. if(testIfB(“true”)){
13. System.out.println(“True”);
14. }else{
15. System.out.println(“Not true”);
16. }
17. }
18. public Boolean testIfB(String str){
19. return Boolean.valueof(str);
20. }
What is the result when method testIfA is invoked?
A. True
B. Not true
C. An exception is thrown at runtime
D. Compilation fails because of an error at line 12.
E. Compilation fails because of an error at line 19.
Answer: ( A )
参考大纲:实用API — 封装类