OCJP视频课堂,具体讲解:https://edu.csdn.net/course/detail/7811

QUESTION 134

Given:
11. class Snoochy {
12. Boochy booch;
13. public Snoochy() { booch = new Boochy(this); }
14. }
15.
16. class Boochy {
17. Snoochy snooch;
18. public Boochy(Snoochy s) { snooch = s; }
19. } And the statements:
21. public static void main(String[] args) {
22. Snoochy snoog = new Snoochy();
23. snoog = null;
24. // more code here
25. }
Which statement is true about the objects referenced by snoog, snooch, and booch immediately after line
23 executes?
A. None of these objects are eligible for garbage collection.
B. Only the object referenced by booch is eligible for garbage collection.
C. Only the object referenced by snoog is eligible for garbage collection.
D. Only the object referenced by snooch is eligible for garbage collection.
E. The objects referenced by snooch and booch are eligible for garbage collection.
Answer: E

23行结束,snooch 和booch都没引用任何对象,可以被垃圾回收器回收。

QUESTION 135
Given:
3. public class Batman {
4. int squares = 81;
5. public static void main(String[] args) {
6. new Batman().go();
7. }
8. void go() {
9. incr(++squares);
10. System.out.println(squares);
11. }
12. void incr(int squares) { squares += 10; }
13. }
What is the result?
A. 81
B. 82
C. 91
D. 92
E. Compilation fails.
F. An exception is thrown at runtime.
Answer: B

一定要记得Java的参数传递全部都是引用~~不变哦~~

QUESTION 136 Given classes defined intwo different files:

1. package util;

2. public class BitUtils {

3. private static voidprocess(byte[] b) {} //注意这里的访问修饰符是private,在类外不能访问,所以选择F

4. }

1. package app;

2. public class SomeApp {

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

4. byte[] bytes = new byte[256];

5. // insert code here

6. }

7. }

What is required at line 5 in classSomeApp to use the process method of BitUtils?

A.   process(bytes);

B.   BitUtils.process(bytes);

C.   app.BitUtils.process(bytes);

D.   util.BitUtils.process(bytes);

E.   import util.BitUtils.*;process(bytes);

F.    SomeApp cannot use the processmethod in BitUtils.

Answer: F

Section: (none)

QUESTION 139

Given the following directory structure:

bigProject

|--source

| |--Utils.java

|

|--classes

|--

And the following

command line invocation: javac -d classes source/Utils.java Assume the current directory is bigProject,
what is the result?
A. If the compile is successful, Utils.class is added to the source directory.
B. The compiler returns an invalid flag error.
C. If the compile is successful, Utils.class is added to the classes directory.
D. If the compile is successful, Utils.class is added to the bigProject directory.
Answer: C

-d classes 是把生成的Utils.class文件放到classes目录中的Unix命令~~

QUESTION 140 Given:

3.     interface Fish { }

4.     class Perch implements Fish { }

5.     class Walleye extends Perch { }

6.     class Bluegill { }

7.     public class Fisherman {

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

9.     Fish f = new Walleye();

10. Walleye w = new Walleye();

11. Bluegill b = new Bluegill();

12. if(f instanceof Perch)System.out.print("f-p ");

13. if(w instanceof Fish)System.out.print("w-f ");

14. if(b instanceof Fish)System.out.print("b-f ");

15. }

16. }

What is the result?

A.   w-f

B.   f-p w-f

C.   w-f b-f

D.   f-p w-f b-f

E.   Compilation fails.

F.    An exception is thrown atruntime.

Answer: B

a instanceof  b,指的是a对象是否是b类或其子类的一个实例对象

或者说a对象是否是实现了b接口的一个实例对象。

w对象是Perch子类的实例对象,f对象实现了Fish接口,b对象没有实现Fish接口。

QUESTION 141
Given:
1. public class Breaker2 {
2. static String o = "";
3. public static void main(String[] args) {
4. z:
5. for(int x = 2; x < 7; x++) {
6. if(x==3) continue;
7. if(x==5) break z;
8. o = o + x;
9. }
10. System.out.println(o);
11. }
12. }
What is the result?
A. 2
B. 24
C. 234
D. 246
E. 2346
F. Compilation fails.

Answer: B

QUESTION 142 Given:

11. public void testIfA() {

12. if (testIfB("True")){

13. System.out.println("True");

14. } else {

15. System.out.println("Nottrue");

16. }

17. }

18. public Boolean testIfB(Stringstr) {

19. return Boolean.valueOf(str);

20. }

What is the result when method testIfA isinvoked?

A.   True

B.   Not true

C.   An exception is thrown atruntime.

D.   Compilation fails because of anerror at line 12.E. Compilation fails because of an error at line 19.

Answer: A

public static Boolean valueOf(String s)返回一个用指定的 String 表示值的 Boolean 值。如果 String 参数不为 null 且在忽略大小写时等于 "true",则返回的 Boolean 表示 true 值。

QUESTION 143 Given:

1. public class Donkey {

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

3. boolean assertsOn = false;

4. assert (assertsOn) : assertsOn= true;

5. if(assertsOn) {

6. System.out.println("assertis on");

7. }

8. }

9. }

If class Donkey is invoked twice, thefirst time without assertions enabled, and the second time with assertionsenabled, what are the results?

A. no output

B. no output

assert is on

C.   assert is on

D.   no output

An AssertionError is thrown.ss

E.   assert is on

An AssertionError is thrown.

QUESTION 144
Given:
31. // some code here
32. try {
33. // some code here
34. } catch (SomeException se) {
35. // some code here
36. } finally {
37. // some code here
38. }
Under which three circumstances will the code on line 37 be executed? (Choose three.)
A. The instance gets garbage collected.
B. The code on line 33 throws an exception.
C. The code on line 35 throws an exception.
D. The code on line 31 throws an exception.
E. The code on line 33 executes successfully.
Answer: BCE

finally有几种情况可以执行:正常执行,发生异常被catch块处理,当然,在catch块内发生的异常也行。

QUESTION 145
Given:
22. public void go() {
23. String o = "";
24. z:
25. for(int x = 0; x < 3; x++) {
26. for(int y = 0; y < 2; y++) {
27. if(x==1) break;
28. if(x==2 && y==1) break z;
29. o = o + x + y;
30. }
31. }
32. System.out.println(o);
33. }
What is the result when the go() method is invoked?
A. 00
B. 0001
C. 000120
D. 00012021
E. Compilation fails.
F. An exception is thrown at runtime.
Answer: C

x=0 y=0 -->o-->00

x=0 y=1 -->o-->00+01->0001

x=1 y=0 1 2--> break;

x=2 y=0 o-->0001+20-->000120

x=2 y=1 break;

最终结果是C

QUESTION 146
Given:
11. static void test() {
12. try {
13. String x = null;
14. System.out.print(x.toString() + " ");
15. }
16. finally { System.out.print("finally "); }
17. }
18. public static void main(String[] args) {
19. try { test(); }
20. catch (Exception ex) { System.out.print("exception "); }
21. }
What is the result?
A. null
B. finally
C. null finally
D. Compilation fails.
E. finally exception
Answer: E

我写了一点测试了一下,发现如果字符串为空(null),那么toString()函数会抛出NullPointerException异常,而不去转换直接输出的时候不会。

[java] view plain copy
  1. package com.xujin;
  2. public class Test {
  3. public static void main(String[] args) {
  4. String s = null;
  5. System.out.println(s);//null
  6. //System.out.println(s.toString());//NullPointerException
  7. System.out.println(s + "hello~~");//nullhello~~
  8. }
  9. }

QUESTION 147 Given:

10. interface Foo {}

11. class Alpha implements Foo {}

12. class Beta extends Alpha {}

13. class Delta extends Beta {

14. public static void main(String[] args ) {

15. Beta x = new Beta();

16. // insert code here

17. }

18. }

Which code, inserted at line 16, willcause a java.lang.ClassCastException?

A.   Alpha a = x;

B.   Foo f = (Delta)x;

C.   Foo f = (Alpha)x;

D.   Beta b = (Beta)(Alpha)x;

Answer: B

架设Foo是飞接口

//Alpha a=x; //将子类转化为父类对象允许,动物 a=狗//Foo f=(Delta)x;//将鸽子抓换为fei接口对象//Foo f=(Alpha)x; //鸟-->飞对象f实现了飞接口的鸟对象

QUESTION 148
Given:
33. try {
34. // some code here
35. } catch (NullPointerException e1) {
36. System.out.print("a");
37. } catch (Exception e2) {
38. System.out.print("b");
39. } finally {
40. System.out.print("c");
41. }
If some sort of exception is thrown at line 34, which output is possible?
A. a
B. b
C. c
D. ac
E. abc
Answer: D

本处意思,如果在34行出现了异常,则最可能是ac或bc,但是没有bc,则选D

QUESTION 149 Given:

11. public class Test {

12. public enum Dogs {collie,harrier, shepherd};

13. public static void main(String[] args) {

14. Dogs myDog = Dogs.shepherd;

15. switch (myDog) {

16. case collie:

17. System.out.print("collie");

18. case default:

19. System.out.print("retriever");

20. case harrier:

21. System.out.print("harrier");

22. }

23. }

24. }

What is the result?

A.   harrier

B.   shepherd

C.   retriever

D.   Compilation fails.

E.   retriever harrier

F.    An exception is thrown atruntime.

Answer: D

d,错在了case default,有default,前面不用加case

ocjp 考试题之六相关推荐

  1. OCJP 考试题之七

    OCJP视频课堂,具体讲解:https://edu.csdn.net/course/detail/7811 QUESTION 150 Click the Exhibit button. Given: ...

  2. OCJP 考试题之九

    OCJP视频课堂,具体讲解:https://edu.csdn.net/course/detail/7811 QUESTION 177 Given: 1.     class TestException ...

  3. OCJP 考试题之八

    OCJP视频课堂,具体讲解:https://edu.csdn.net/course/detail/7811 QUESTION 139 Giventhe following directory stru ...

  4. ORACLE认证考试之ocjp 考试题之四

    OCJP视频课堂,具体讲解:https://edu.csdn.net/course/detail/7811 QUESTION 73 Given: 10: public class Hello { 11 ...

  5. matlab画图(plot)命令

    原创 xiaotao_1 最后发布于2018-01-18 19:55:25 阅读数 56917 收藏 发布于2018-01-18 19:55:25 分类专栏: matlab 版权声明:本文为博主原创文 ...

  6. OCJP Oracle认证Java程序员考试题库分享

    1z0-808 Java SE 8 Programmer I 题库 pdf文档一共197页. 点击链接获取

  7. 不看OCJP考题你永远不知道自己的JAVA基础有多差(一)

    虽然在国内IT业内各种考证被许多牛人不齿,用人单位也往往不做硬性要求,但是自从SUN公司被ORACLE收购之后,JAVA的认证考试的难度是有目共睹的,目前传出的消息OCJP的一次通过率只有10%左右, ...

  8. 2022年广东省安全员A证第三批(主要负责人)考试题模拟考试题库模拟考试平台操作

    题库来源:安全生产模拟考试一点通公众号小程序 2022广东省安全员A证第三批(主要负责人)考题是广东省安全员A证第三批(主要负责人)复训题库仿真模拟预测!2022年广东省安全员A证第三批(主要负责人) ...

  9. 【无2022起重信号司索工(建筑特殊工种)考试题模拟考试题库及模拟考试

    题库来源:安全生产模拟考试一点通公众号小程序 2022起重信号司索工(建筑特殊工种)考题为起重信号司索工(建筑特殊工种)上岗证题目考前押题!2022起重信号司索工(建筑特殊工种)考试题模拟考试题库及模 ...

  10. 2022年中式面点师(高级)特种作业证考试题库及模拟考试

    题库来源:安全生产模拟考试一点通公众号小程序 2022起重信号司索工(建筑特殊工种)考题为起重信号司索工(建筑特殊工种)上岗证题目考前押题!2022起重信号司索工(建筑特殊工种)考试题模拟考试题库及模 ...

最新文章

  1. 消息积压在消息队列里怎么办
  2. Domino/Xpages Bootstrap 动态生成首页功能
  3. 五种方法创建 Java 对象,你知道几种呢?
  4. MFC导出对话框类DLL的实现
  5. 金额输入框校验和自动校正、支持指定任意位数小数decimal、支持只能输入整数、支持是否允许输入负数等功能
  6. 《分拣机械臂测试》- 端拾器最大吸力测试
  7. web 3d 资源库大全
  8. 前端技术栈---Vue(1)安装与初始化
  9. 一位北美 IT 技术人教你如何破局
  10. m118w重置墨粉_富士施乐 Fuji Xerox DocuPrint M118w 加粉及清零
  11. msg1500说明书_拆解电信定制 瑞斯达康MSG1500 双频路由器
  12. 知道一点怎么设直线方程_已知两点坐标怎样求直线方程
  13. 远程实时调试手机上的web页面
  14. Poco库使用:文件压缩和解压缩
  15. (AAAI-2019)用于行人重识别的水平金字塔匹配
  16. 基于c语言实现的个人理财系统,基于Android的个人理财系统—设计和实现-论文最终版.doc...
  17. 读书笔记-《版面设计的原理》
  18. ET部署到docker,用docker实现快速部署ET分布式服务器(一)
  19. 一个普通人不靠工资的收入有什么?
  20. github 开元项目

热门文章

  1. matlab 三维 作图 坐标轴_matlab三维作图教程
  2. Android_Data 资料
  3. win10安装Visual Stdio2010教程及问题解决办法
  4. 记一次绕过安全狗与360艰难提权
  5. 极品抓鸡教程36课笔记
  6. 【原创】基于Qt5.14的一站式安卓开发环境搭建
  7. tf卡可以自己裁剪成nm卡_真假TF卡鉴定方法
  8. 基于信息论的编码技术
  9. 负债均衡(三)下载安装Nginx
  10. 从微软重返诺基亚:Juha Alakarhu是何许人也?