博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OCJP 考试题之七
阅读量:7121 次
发布时间:2019-06-28

本文共 2289 字,大约阅读时间需要 7 分钟。

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:

  1. static void test() throwsRuntimeException {

  2. try {

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

  4. throw new RuntimeException();

  5. }

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

  7. }

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

  9. try { test(); }

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

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

  12. }

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. }

  6. public class Tree extends Plant{

  7. public void growFruit() { }

  8. public void dropLeaves() { }

  9. }

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:

  1. class Line {

  2. public static class Point {}

  3. }

  4. class Triangle {

  5. // insert code here

  6. }

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:

  1. class Nav{

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

  3. }

  4. public class Sprite{

  5. // insert code here

  6. }

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)

转载于:https://blog.51cto.com/2096101/2136491

你可能感兴趣的文章
选择编程字体
查看>>
小程序日常工作总结
查看>>
mySql学习笔记:比sql server书写要简单
查看>>
ajax封装
查看>>
例题9-6 UVa11400 Lighting System Design(DP)
查看>>
PAT1087 All Roads Lead to Rome (30)(最短路径+dfs+回溯)
查看>>
learn go function callback
查看>>
Arcgis Engine 添加一个Symbol符号样式步骤
查看>>
kafka 控制台命令
查看>>
alpha冲刺10
查看>>
睡觉了~~
查看>>
【LeetCode】28 - Implement strStr()
查看>>
Node.js与Sails~Model数据模型
查看>>
[转]没有找到 MFC42D.DLL,因此这个应用程序未能启动。重新安装应用程序可能会修复此问题。解决方法!...
查看>>
我再也不-或许永远不-用zend studio-受够了!
查看>>
软件工程(2019)第三次作业
查看>>
Java性能调优
查看>>
第 6 章 存储 - 039 - Data Volume 之 bind mount
查看>>
异步IO
查看>>
MySQL
查看>>