QUESTION 150

Click the Exhibit button. Given: ClassA a = new ClassA(); a.methodA(); What is the result?

A. Compilation fails.
B. ClassC is displayed.
C. The code runs with no output.
D. An exception is thrown at runtime.
Answer: D

问题出在第24行,classC还没有new一个,就直接用函数getValue(),NullPointerException会被抛出

public ClassC classC;该行代码没有new出来ClassC,空指针异常;

QUESTION 151 Given:

11. static void test() throwsRuntimeException {

12. try {

13. System.out.print("test");

14. throw new RuntimeException();

15. }

16. catch (Exception ex) { System.out.print("exception"); }

17. }

18. public static voidmain(String[] args) {

19. try { test(); }

20. catch (RuntimeException ex) {System.out.print("runtime "); }

21. System.out.print("end");

22. }

What is the result?

A.   test end

B.   Compilation fails.

C.   test runtime end

D.   test exception end

E.   A Throwable is thrown by mainat runtime.

Answer: D

QUESTION 152 Given:

1. public class Plant {

2. private String name;

3. public Plant(String name) {this.name = name; }

4. public String getName() { returnname; }

5. }

1. public class Tree extends Plant{

2. public void growFruit() { }

3. public void dropLeaves() { }

4. }

Which statement is true?

A.   The code will compile withoutchanges.

B.   The code will compile if publicTree() { Plant(); } is added to the Tree class.

C.   The code will compile if publicPlant() { Tree(); } is added to the Plant class.

D.   The code willcompile if public Plant() { this("fern"); } is added to the Plantclass.

E.   The code will compile if publicPlant() { Plant("fern"); } is added to the Plant class.

Answer: D

Section: (none)

Plant需要一个无参默认构造函数,因为子类带一个参数的构造函数

QUESTION 153

Given:

10. class Line {

11. public static class Point {}

12. }

13.

14. class Triangle {

15. // insert code here

16. }

Which code, inserted at line 15, createsan instance of the Point class defined in Line?

A.   Point p = new Point();

B.   Line.Point p = newLine.Point();

C.   The Point class cannot beinstatiated at line 15.

D.   Line l = new Line() ; l.Point p= new l.Point();

Answer: B

QUESTION 154 Given:

10. class Nav{

11. public enum Direction { NORTH,SOUTH, EAST, WEST }

12. }

13. public class Sprite{

14. // insert code here

15. }

Which code, inserted at line 14, allowsthe Sprite class to compile?

A.   Direction d = NORTH;

B.   Nav.Direction d = NORTH;

C.   Direction d = Direction.NORTH;

D.   Nav.Direction d = Nav.Direction.NORTH;

Answer: D

Section: (none)

最新文章

  1. js实现StringBuffer
  2. python __call__ 内置函数的使用
  3. DateTime 详解
  4. sass编译
  5. zip函数
  6. 总结的一些PHP开发中的tips
  7. ARM指令集(上)
  8. 设置PL/SQL Developer记住用户名密码
  9. ios字体大小适应不同屏幕
  10. Hibernate最简单教程
  11. 《JAVA程序设计与实例》记录与归纳--类与对象
  12. Java 接口基础详解
  13. 服务器配置java
  14. 利用httpd配置虚拟目录创建下载站点
  15. AI人工智能顶级实战工程师 课程大纲
  16. 如何利用sql 读取辅表的最大max 和第二最大max。。。。
  17. react-router与react-router-dom使用时的区别
  18. WebPage设计专业术语
  19. MyEclipse配置Struts2的本地工作空间中的DTD约束文件
  20. unity---gameScreen 的Stats参数

热门文章

  1. Geatpy遗传算法在曲线寻优上的初步探究
  2. c++虚继承与虚函数
  3. 图片人脸检测(OpenCV版)
  4. Ajax中post后台.net MVC中Controller的路径问题。
  5. Visual Studio AI 离线模型训练(window 7)
  6. Daily Scrumming* 2015.10.26(Day 7)
  7. 对Largest函数的测试
  8. C#窗体——四则运算
  9. 【TCP/IP详解 卷一:协议】第六章:DHCP 和自动配置
  10. Node.js记录