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 ...
随机推荐
- windows下在idea用maven导入spark2.3.1源码并编译并运行示例
一.前提 1.配置好maven:intellij idea maven配置及maven项目创建 2.下载好spark源码: 二.导入源码: 1.将下载的源码包spark-2.3.1.tgz解压(E:\ ...
- VMware两台虚拟机之间文件共享
虚拟机A的文件拷贝到虚拟机B scp[参数][原路径][目标路径] eg: scp -r root@192.168.0.172:/home/rookie/下载/ /home/rooookie/下载/ ...
- 从零开始的Python学习Episode 19——面向对象(2)
面向对象之继承 继承是一种创建新类的方式,新建的类可以继承一个或多个父类(python支持多继承),父类又可称 为基类或超类,新建的类称为派生类或子类. 子类会“”遗传”父类的属性,从而解决代码重用问 ...
- redis使用Jackson2JsonRedisSerializer序列化问题
一.spring boot 集成Redis方法 依赖 <!--redis--> <dependency> <groupId>org.springframework. ...
- 【深度学习的实用层面】(一)训练,验证,测试集(Train/Dev/Test sets)
在配置训练.验证.和测试数据集的过程中做出正确的决策会更好地创建高效的神经网络,所以需要对这三个名词有一个清晰的认识. 训练集:用来训练模型 验证集:用于调整模型的超参数,验证不同算法,检验哪种算法更 ...
- node jade模板数据库操作
/* Navicat MySQL Data Transfer Source Server : localhost Source Server Version : 50519 Sourc ...
- “Hello World!“”团队第七周召开的第三次会议
今天是我们团队“Hello World!”团队第七周召开的第三次会议.博客内容: 一.会议时间 二.会议地点 三.会议成员 四.会议内容 五.todo list 六.会议照片 七.燃尽图 八.代码 一 ...
- 冲刺One之站立会议5 /2015-5-18
2015-5-18 服务器部分大体已经完工,现在我们主要是在把登陆界面和服务器组装起来,这个过程是很让人头痛的,以为其中涉及到了很多网络协议.网络编程的知识,由于之前我们没有接触过所以实现起来会觉得很 ...
- SE Springer小组《Spring音乐播放器》可行性研究报告一、二
1 引言 1.1编写目的 <软件工程>课程,我们团队计划开发一个音乐播放器.本文档是基于网络上现有的音乐播放器的特点,团队计划实现的音乐播放器功能和团队人员的综合实力等情况,说明该软件开发 ...
- BETA-7
前言 我们居然又冲刺了·七 团队代码管理github 站立会议 队名:PMS 530雨勤(组长) 过去两天完成了哪些任务 经过分析发现,为提升速率估测的可靠性,目前最具可改造性的参数为帧间间隔,调用参 ...