Java考试题之七
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考试题之七的更多相关文章
- java设计模式之七装饰器模式(Decorator)
顾名思义,装饰模式就是给一个对象增加一些新的功能,而且是动态的,要求装饰对象和被装饰对象实现同一个接口,装饰对象持有被装饰对象的实例,关系图如下: Source类是被装饰类,Decorator类是一个 ...
- 玩玩微信公众号Java版之七:自定义微信分享
前面已经学会了微信网页授权,现在微信网页的功能也可以开展起来啦! 首先,我们先来学习一下分享,如何在自己的页面获取分享接口及让小伙伴来分享呢? 今天的主人公: 微信 JS-SDK, 对应官方链接为:微 ...
- Java设计模式之七 ----- 享元模式和代理模式
前言 在上一篇中我们学习了结构型模式的组合模式和过滤器模式.本篇则来学习下结构型模式最后的两个模式, 享元模式和代理模式. 享元模式 简介 享元模式主要用于减少创建对象的数量,以减少内存占用和提高性能 ...
- Java考试题之十
QUESTION 230 Given: 10. class One { 11. public One foo() { return this; } 12. } 13. class Two extend ...
- Java考试题之九
QUESTION 177 Given: 1. class TestException extends Exception { } 2. class A { 3. public ...
- Java考试题之八
QUESTION 139 Giventhe following directory structure: bigProject |--source | |--Utils.java ||--classe ...
- Java考试题之六
QUESTION 134 Given:11. class Snoochy {12. Boochy booch;13. public Snoochy() { booch = new Boochy(thi ...
- Java考试题之五
QUESTION 102 Given: 23. Object [] myObjects = { 24. new Integer(12), 25. new String("foo") ...
- Java考试题之四
QUESTION 73 Given: 10: public class Hello { 11: String title; 12: int value; 13: public Hello() { 14 ...
随机推荐
- Netty源码分析第2章(NioEventLoop)---->第5节: 优化selector
Netty源码分析第二章: NioEventLoop 第五节: 优化selector 在剖析selector轮询之前, 我们先讲解一下selector的创建过程 回顾之前的小节, 在创建NioEv ...
- 高可用OpenStack(Queen版)集群-16.Nova集成Ceph
参考文档: Install-guide:https://docs.openstack.org/install-guide/ OpenStack High Availability Guide:http ...
- ms cms
很多开源CMS,都是半开源或假开源. 看看微软的CMS怎么样吧.这么著名的CMS,下载网址不好找. https://orchard.codeplex.com/SourceControl/latest
- Python20-Day06
常用模块 一.random模块 import random # print(random.random()) #打印0-1之间的小数 # print(random.randint(1,3)) #大于等 ...
- Python20-Day05
一.模块与包 1.模块 什么是模块? 在python中,模块可以分为四个通用类别: 1. 使用python编写的.py文件 2. 已经被编译为共享库或DLL的c或者c++扩展 3. 把一系列模块组织到 ...
- android学习-2 (AVD 创建)
在Android studio的tools下选择AVD manager 按照指示选择相应的硬件和系统映像. 在模拟器中运行应用 选择RUN APP 选择RUN时,并不只运行应用,还会处理运行应用所需要 ...
- OO前三次作业简单总结
随着几周的进行,OO课堂已经经历过三次课下作业.在这三次作业中,我被扣了一些分数,也发现了自己几次作业中一些存在的共同的问题. 首先以第三次作业为例分析,我程序的类图如下 一共九个类,其中Als_sc ...
- C#窗体——四则运算
用户需求:程序能接收用户输入的整数答案,并判断对错程序结束时,统计出答对.答错的题目数量.补充说明:0——10的整数是随机生成的用户可以选择四则运算中的一种用户可以结束程序的运行,并显示统计结果.在此 ...
- BNUOJ 52318 Be Friends prim+Trie
题目链接: https://acm.bnu.edu.cn/v3/problem_show.php?pid=52318 B. Be Friends Case Time Limit: 2500msMemo ...
- java编程的一些注意事项
下面是参考网络资源和总结一些在java编程中尽可能做到的一些地方 1.尽量在合适的场合使用单例 使用单例可以减轻加载的负担,缩短加载的时间,提高加载的效率,但并不是所有地方都适用于单例,简单来说,单例 ...