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)

Java考试题之七的更多相关文章

  1. java设计模式之七装饰器模式(Decorator)

    顾名思义,装饰模式就是给一个对象增加一些新的功能,而且是动态的,要求装饰对象和被装饰对象实现同一个接口,装饰对象持有被装饰对象的实例,关系图如下: Source类是被装饰类,Decorator类是一个 ...

  2. 玩玩微信公众号Java版之七:自定义微信分享

    前面已经学会了微信网页授权,现在微信网页的功能也可以开展起来啦! 首先,我们先来学习一下分享,如何在自己的页面获取分享接口及让小伙伴来分享呢? 今天的主人公: 微信 JS-SDK, 对应官方链接为:微 ...

  3. Java设计模式之七 ----- 享元模式和代理模式

    前言 在上一篇中我们学习了结构型模式的组合模式和过滤器模式.本篇则来学习下结构型模式最后的两个模式, 享元模式和代理模式. 享元模式 简介 享元模式主要用于减少创建对象的数量,以减少内存占用和提高性能 ...

  4. Java考试题之十

    QUESTION 230 Given: 10. class One { 11. public One foo() { return this; } 12. } 13. class Two extend ...

  5. Java考试题之九

    QUESTION 177 Given: 1.     class TestException extends Exception { } 2.     class A { 3.     public ...

  6. Java考试题之八

    QUESTION 139 Giventhe following directory structure: bigProject |--source | |--Utils.java ||--classe ...

  7. Java考试题之六

    QUESTION 134 Given:11. class Snoochy {12. Boochy booch;13. public Snoochy() { booch = new Boochy(thi ...

  8. Java考试题之五

    QUESTION 102 Given: 23. Object [] myObjects = { 24. new Integer(12), 25. new String("foo") ...

  9. Java考试题之四

    QUESTION 73 Given: 10: public class Hello { 11: String title; 12: int value; 13: public Hello() { 14 ...

随机推荐

  1. TCP协议数据包及攻击分析

    TCP/IP协议栈中一些报文的含义和作用 URG: Urget pointer is valid (紧急指针字段值有效) SYN: 表示建立连接 FIN: 表示关闭连接 ACK: 表示响应 PSH: ...

  2. tensorflow enqueue_many传入多个值的列表传入异常问题————Shape () must have rank at least 1

    tf 的队列操作enqueue_many传入的值是列表,但是放入[]列表抛异常 File "C:\Users\lihongjie\AppData\Local\Programs\Python\ ...

  3. JDK自带的监控工具方法

    一.概述       SUN 的JDK中的几个工具,非常好用.秉承着有免费,不用商用的原则.以下简单介绍一下这几种工具.(注:本文章下的所有工具都存在JDK5.0以上版本的工具集里(jdk的bin目录 ...

  4. jsp九大内置对象之一request

    request对象,目的是用来获取客户端的请求. 主要方法有: request.getMethod();                      // 获取提交请求的方式 request.getPr ...

  5. Android笔记-5-EditText密码和Checkbox二选一

    EditText密码:明文和密文 密文: public class MainActivity extends Activity { private EditText password = null; ...

  6. 微服务注册与发现 —— eureka

    基础概念 在微服务系统中,服务的注册和发现是第一步,常用的有: Eureka:https://github.com/Netflix/eureka Zookeeper:https://zookeeper ...

  7. C#简单窗体应用程序(一)

    使用C#创建控制台应用程序的基本步骤: (1)创建项目: (2)用户界面设计: (3)属性设置: (4)编写程序代码: (5)保存.调试.运行: 例题:创建一个Windows窗体应用程序,在窗体中添加 ...

  8. 404 Note Found团队-项目UML设计

    目录 团队信息 分工选择 课上分工 课下分工 ToDolist alpha版本要做的事情 燃尽图 UML 用例图 状态图 活动图 类图 部署图 实例图 对象图 时序图 包图 通信图 贡献分评定 课上贡 ...

  9. angularJS1笔记-(14)-自定义指令(scope)

    index.html: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  10. Struts1 工作流程

    一个老项目的维护 , 需要学习一下 Struts1. struts1运行步骤 1.项目初始化:项目启动时加载 web.xml,struts1 的总控制器 ActionServlet 是一个 Servl ...