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 ...
随机推荐
- 剑指offer试题(PHP篇三)
21.栈的压入.弹出序列 题目描述 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序,序列4 ...
- centos7.6 安装nginx-1.14.2
一.安装所需依赖环境 yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel 二.下载nginx官方源 ...
- 03_set slice的时间复杂度
set slice O(n+k) 使用切片赋值来解释set slice的时间复杂度 (1) 对li[0:3]赋值首先会删除1,2,3,空出来的位置被后面的元素依次向前移动填充,由del slice 得 ...
- [Github] Github使用教程
前言 Github是一个面向开源及私有软件项目的托管平台.它可以免费使用,并且速度快速,拥有超多的用户.是目前管理软件开发和发现已有代码的首选平台.下面将向Github新手介绍相关操作. 正文 注册 ...
- BOM 头是什么,怎么除去
WINDOWS自带的记事本,在保存一个以 UTF-8 编码的文件时,会在文件开始的地方插入三个不可见的字符(0xEF 0xBB 0xBF,即BOM).它是一串隐藏的字符,用于让记事本等编辑器识别这个文 ...
- SQL-Server collation, what is it and how to change db/column collation
The thing about collations is that although database have it's own collation, every table, and every ...
- 如何在静态方法或非Spring Bean中注入Spring Bean
在项目中有时需要根据需要在自己new一个对象,或者在某些util方法或属性中获取Spring Bean对象,从而完成某些工作,但是由于自己new的对象和util方法并不是受Spring所 ...
- Scrum Meeting 11 -2014.11.17
今天和其他两个小组讨论了关于整合问题,在数据库连接等具体方面上还需要继续商讨. 我们小组内部讨论了,这周还是需要在处理整合的同时做项目整体的测试与改进的. Member Today’s task Ne ...
- 【Alpha版本发布】爬虫队长正在待命!
一.基础功能简介 本团队的爬虫能够从网上搜索相关内容, 并归类,把所爬到的网页或各种类型的文档下载到本地上. 上届团队Beta版本爬虫的主要功能如下: a)可爬取网页,问答页并进行问答文件分类. b) ...
- linux上传的命令
pscp D:\apache-tomcat-8.0.38\webapps\GameDataServer.zip root@112.74.32.215:/usr/local/tools/tomcat/a ...