Question1:

Given the code fragment:public class Test {static int count = 0; //static会保留值int i = 0;
public void changeCount() {while (i < 5) {i++;count++;}}public static void main(String[] args) {Test check1 = new Test(); //5Test check2 = new Test(); //10check1.changeCount(); //5check2.changeCount(); //10System.out.print(check1.count + ":" + check2.count);}
}
What is the result?
A.10 : 10
B.5 : 5
C.5 : 10
D.Compilation fails
Answer: A
标签:static关键字

Static的值只有一份 并且会保留永远执行最新

Question2:

public static void main(String[] args) {String product = "Pen";product.toLowerCase(); //仅小写product.concat(" BOX".toLowerCase()); //连接 中间有空格System.out.println(product.substring(4, 6));
}
What is the result?
A.box
B.nbo
C.bo
D.nb
E.An exception is thrown at runtime
Answer: E
标签:String关键字

System.out.println(product.substring(4, 6));

Product是指String product = "Pen";

所以截取不到

Question3:

Which three are advantages of the Java exception mechanism?
A.Improves the program structure because the error handling code is separated fromthe normal program function
B.Provides a set of standard exceptions that covers all the possible errors
C.Improves the program structure because the programmer can choose where to handle exceptions
D.Improves the program structure because exceptions must be handled in themethod in which they occurred
E.Allows the creation of new exceptions that are tailored to the particular program being created
Answer: ACE
标签:异常  

Question4:

Given the code fragment:
public class Person {String name;int age = 25;public Person(String name) {this(); // line n1 //this()里面没有参数 而方法有参数setName(name);}public Person(String name, int age) {Person(name); // line n2 //不能直接调用方法 需要newsetAge(age);}// setter and getter methods go herepublic String show() {return name + "" + age + "";}public static void main(String[] args) {Person p1 = new Person("Jesse");Person p2 = new Person("Walter", 52);System.out.println(p1.show());System.out.println(p2.show());}
}
What is the result?
A.Jesse 25Walter 52
B.Compilation fails only at line n1
C.Compilation fails only at line n2
D.Compilation fails at both line n1 and line n2
Answer: D
标签:this关键字

This()关键字里面的参数要和上边的参数对应

不能直接调用方法名 需要new

Question5:

Given:
class Mid {public int findMid(int n1, int n2) {return (n1 + n2) / 2;}
}
class Calc extends Mid {public static void main(String[] args) {int n1 = 22, n2 = 2;// insert code here}
}
Which code fragments, when inserted at // insert code here, enable the code tocompile and print 12?
A.Calc c = new Calc();
int n3 = c.findMid(n1,n2);
int n3 = super.findMid(n1,n3); //super()不能和static方法放在一起
B.Calc c = new Mid(); //子类指向父类对象(错)
int n3 = c.findMid(n1, n2);
C.Mid m1 = new Calc();
int n3 = m1.findMid(n1, n2);
D.int n3 = Calc.findMid(n1, n2); //错误,带static方法只能调用static方法
Answer:  C
标签:继承

Question6:

Given the code fragment:
LocalDate date1 = LocalDate.now(); //2014-06-20
LocalDate date2 = LocalDate.of(2014,6,20); //2014-06-20
LocalDate date3 = LocalDate.parse("2014-06-20",DateTimeFormatter.ISO_DATE); //2014-06-20
System.out.println("date1 = "+date1);
System.out.println("date2 = "+date2);
System.out.println("date3 = "+date3);
Assume that the system date is June 20, 2014. What is the result?
A.A DateParseException is thrown at runtime
B.date1 = 2014-06-20
date2 = 2014-06-20
date3 = 2014-06-20
C.date1 = 06/20/2014
date2 = 2014-06-20
date3 = Jun 20, 2014
D.Compilation fails
Answer: B
标签:LocalDate关键字

Question7:

Given the code fragment:
public class For {public static void main(String[] args) {int[] lst = { 1, 2, 3, 4, 5, 4, 3, 2, 1 };int sum = 0;for (int frnt = 0, rear = lst.length - 1; frnt < 5 && rear >= 5; frnt++, rear--) {sum = sum + lst[frnt] + lst[rear];}System.out.println(sum);}
}
A.20
B.25
C.29
D.Compilation fails
E.AnArrayIndexOutOfBoundsException is thrown at runtime
Answer:A
标签:数组,逻辑运算符

数组下标从0开始  长度从1开始

Question8:

Given the code fragment:
public static void main(String[] args) {String date = LocalDate.parse("2014-05-04").format(DateTimeFormatter.ISO_DATE_TIME);System.out.println(date);
}
What is the result?
A.May 04, 2014T00:00:00.000
B.2014-05-04T00:00: 00. 000
C.5/4/14T00:00:00.000
D.An exception is thrown at runtime
Answer: D
标签:LocalDate关键字

parse("2014-05-04")

ISO_DATE_TIME)

两者格式不一致 不能相互转换

Question9:

Given the code fragment:
public static void main(String[] args){double discount = 0;int qty = Integer.parseInt(args[0]);//line n1;
}
And given the requirements:
If the value of the qty variable is greater than or equal to 90, discount = 0.5 If the
value of the qty variable is between 80 and 90, discount = 0.2
Which two code fragments can be independently placed at line n1 to meet the
requirements?
A.if(qty>=90){discount=0.5;}
if(qty>80&&qty<90){ discount = 0.2;}
B.discount = (qty>=90)?0.5:0;
discount = (qty>80)?0.2:0; //80-90之间
C.discount = (qty>=90)?0.5:(qty>80)?0.2:0;
D.if(qty>80&&qty<90){
discount = 0.2;
}else{               //不能加else 不会进入到下一个循环discount = 0;
}
if(qty>=90){discount = 0.5;
}else{discount = 0;
}
E.discount = (qty>80)?0.2:(qty>=90)?0.5:0; //>80都会=0.2
Answer: AC
标签:逻辑运算符,三目运算符

三元表达式 boolean?true:flase

三元运算符的嵌套 Boolean ? true : boolean ? ture : false

Question10:

Given:
publicclass Circle {double radius;publicdouble area;publicCircle(double r) {radius = r;}publicdouble getRadius() {return radius;}publicvoid setRadius(double r) {radius = r;}publicdouble getArea() {  return Math.PI * radius * radius;//或}
}
staticclass App {publicstaticvoid main(String[] args) {Circle c1 = new Circle(17.4);c1.area = Math.PI*c1.getRadius()*c1.getRadius();}
}
The class is poorly encapsulated. You need to change the circle class to compute
and return the area instead.
Which modifications are necessary to ensure that the class is being properly
encapsulated?
A.Remove the area field. //删除后 后面就不能调用该变量
B.Change the getArea( ) method as follows:
public double getArea ( ) { return Match.PI * radius * radius; }
C.Add the following method:
public double getArea ( ) {area = Match.PI * radius * radius; } //方法名和参数列表都相同
D.Change the cacess modifier of the SerRadius ( ) method to be protected.
Answer: D
标签:访问修饰符

Question11:

Given the code fragment:
publicstaticvoid main(String[] args) {int row = 10;for (; row > 0;) {int col = row;while (col >= 0) {System.out.println(col + "");col -= 2;}row = row / col;}
}
What is the result?
A.10 8 6 4 2 0
B.10 8 6 4 2
C.AnArithmeticException is thrown at runtime
D.The program goes into an infinite loop ou
E.Compilation fails
Answer: A
标签:循环语句

Question12:

Given:
publicclass Test {publicstaticvoid main(String[] args) {List<Patient> ps = new ArrayList<Patient>();Patient p2 = new Patient("Mike");ps.add(p2);
//insert code here  //line n14int f = ps.indexOf(p2);if(f>=0){System.out.println("Mike Found");}}staticclass Patient {
String name;public Patient(String name) {this.name = name;}}
}
Which code fragment, when inserted at line 14, enables the code to print MikeFound?
A.int f = ps.indexOf {new patient ("Mike")}; //提取成一个成员变量MIKe
B.int f = ps.indexOf (patient("Mike")); // 需要new一个对象patient 再把Mike提取成成员变量
C.patient p = new Patient ("Mike");int f = pas.indexOf(P) //把Mike提取成成员变量
D.int f = ps.indexOf(p2);
Answer: D
标签:集合

Question13:

Given the for loop construct:
for ( expr1 ; expr2 ; expr3 ) {
statement;
}
Which two statements are true?
A.  This is not the only valid for loop construct; there exits another form of for loop
constructor. //这不是循环构造的唯一有效方法;存在另一种形式的for循环构造函数。
B.  The expression expr1 is optional. it initializes the loop and is evaluated once, as
the loop begin. //表达式expr1是可选的。它初始化循环,并在循环开始时计算一次。
C.  When expr2 evaluates to false, the loop terminates. It is evaluated only after each //第一次评估没有迭代
iteration through the loop. //当expr2的计算结果为false时,循环终止。它仅在循环的每次迭代后进行评估
D.  The expression expr3 must be present. It is evaluated after each iteration through
the loop. //表达式expr3必须存在。在通过循环的每次迭代之后对其进行评估。
Answer: A,B
标签:循环语句

Question14:

Which three statements are true about the structure of a Java class?
A.A class can have only one private constructor.
B.A method can have the same name as a field.
C.A class can have overloaded static methods.
D.A public class must have a main method.
E.The methods are mandatory components of a class.
F.The fields need not be initialized before use.
Answer: BCF
标签:类

B方法名可以相同

C类可以具有重载的静态方法

F 使用前无需初始化字段

Question15:

View the exhibit.
class MissingInfoException extends Exception{ }
class AgeOutofRangeException extends Excepiton{ }
class Candidate{String name;int age;Candidate(String name,int age) throws Exception{if(name==null){throw new MissingInfoException();}else if(age<=10||age>=150){throw new AgeOutofRangeException();}else{this.name=name;this.age=age;}}public String toString(){return name+"age:"+age;}
}
Given the code fragment:
4.public class Test {
5.  public static void main(String[] args) {
6.      Candidate c=new Candidate("James",20);
7.      Candidate c1=new Candidate("Williams",32);
8.      System.out.println(c);
9.      System.out.println(c1);
10. }
11. }
Which change enables the code to print the following?
James age: 20
Williams age: 32
A.Replacing line 5 with public static void main (String [] args) throws
MissingInfoException, AgeOutofRangeException { //缺少一个异常
B.Replacing line 5 with public static void main (String [] args) throws.Exception {
C.Enclosing line 6 and line 7 within a try block and adding:
catch(Exception e1) { //code goes here}
catch (missingInfoException e2) { //code goes here} catch (AgeOutofRangeExceptione3) {//code goes here}
D.Enclosing line 6 and line 7 within a try block and adding:
catch (missingInfoException e2) { //code goes here} catch (AgeOutofRangeExceptione3) {//code goes here} //缺少一个异常
Answer: C
标签:异常,异常的处理

Question16:

Given the code fragment:
public static void main(String[] args) {
int iArray[] = {65, 68, 69};
iArray[2] = iArray[0];
iArray[0] = iArray[1];
iArray[1] = iArray[2];
for (int element : iArray) {
System.out.print(element + " ");
}
}
A.68, 65, 69
B.68, 65, 65
C.65, 68, 65
D.65, 68, 69
E.Compilation fails
Answer: B
标签:数组

每一次替换都变成一个新的数组

新的数组在进行替换

Question17:

Given:
public class Test {
public static void main(String[] args) {
int day = 1;
switch (day) {
case "7": System.out.print("Uranus");
case "6": System.out.print("Saturn");
case "1": System.out.print("Mercury");
case "2": System.out.print("Venus");
case "3": System.out.print("Earth");
case "4": System.out.print("Mars");
case "5": System.out.print("Jupiter");
}
}
}
Which two modifications, made independently, enable the code to compile and run?
A.Adding a break statement after each print statement
B.Adding a default section within the switch code-block
C.Changing the string literals in each case label to integer
D.Changing the type of the variable day to String
E.Arranging the case labels in ascending order
Answer: CD
标签:switch-case语句

int day = 1; int类型

case "7":  string类型

要对应

Switch(byte,short,int,char,string,)

变量可以是byte、short、int、char、[String(JDK7+)时可使用]  其中变量|表达式不能是long  String  boolean类型!

Question18:

Given:
publicclass Product {int id;String name;public Product(int id, String name) {this.id = id;this.name = name;}
}
And given the code fragment:
Product p1 = new Product(101, "pen");
Product p2 = new Product(101, "pen");
Product p3 = p1;
boolean ans1 = p1 == p2;
boolean ans2 = p1.name.equals(p2.name);
System.out.print(ans1 + ":" + ans2);
What is the result?
A.true:true
B.true:false
C.false:true
D.false:false
Answer: C
标签:String关键字,equals关键字

Question19:

Given:
publicclass CD {int r;CD(int r) {this.r = r;}class DVD extends CD {int c;DVD(int r, int c) {super(r);this.c=c;}}
}
Which code fragment should you use at line n1 to instantiate the dvd objectsuccessfully?
A.super.r=r; //super()
this.c=c;
B.super(r); //super()和this()不能共存 且都必须在构造方法的第一行
this(c);
C.super(r);
this.c=c;
D.this.c=r;
super(c); //super()要放在第一行
Answer: C
标签:this关键字 ,继承

super()和this()不能共存 且都必须在构造方法的第一行

Question20:

Given:
Public class Alpha {int ns;Static int s;public Alpha(int ns) {if (s<ns) {s=ns;this.ns=ns;}}void doPrint(){System.out.println("ns = "+ns+" s = "+s);}
}
And,
publicclass TestA {publicstaticvoid main(String[] args) {Alpha ref1=new Alpha(50);Alpha ref2=new Alpha(125);Alpha ref3=new Alpha(100);ref1.doPrint();ref2.doPrint();ref3.doPrint();}
}
What is the result?
A.ns = 50 s = 125
ns = 125 s = 125
ns = 100 s = 125
B.ns = 50 s = 125
ns = 125 s = 125
ns = 0 s = 125
C.  ns = 50 s = 50
ns = 125 s = 125
ns = 100 s = 100
D.  ns = 50 s = 50
ns = 125 s = 125
ns = 0 s = 125
Answer: B
标签:static关键字

Static修饰的成员变量只有一份 不会因为创建多个对象有多份  永远执行最新

局部变量:在方法体中定义的变量,局部变量只在定义它的方法中有效

成员变量:就是全局变量,是整个源程序都有效的变量

OCJP考试习题(1z0-808)(一)相关推荐

  1. 2017年vb计算机考试,2017年计算机二级VB考试习题及答案

    2017年计算机二级VB考试习题及答案 习题二 1.在窗体上画一个名称为Text1的文本框,一个名称为Command1的命令按钮,然后编写如下事件过程和通用过程: Private Sub Comman ...

  2. c语言程序设计题2015,2015年荐C语言程序设计等级考试习题汇编.doc

    C语言程序设计等级考试习题汇编 1.设计程序:数列第1项为81,此后各项均为它前1项的正平方根,统计该数列前30项之和,并以格式"%.3f"写到考生目录中Paper子目录下的新建文 ...

  3. 计算机三级网络技术综合题解析,计算机三级网络技术上机考试习题答案及解析...

    计算机三级网络技术上机考试习题答案及解析 (109页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 29.9 积分 三级网络技术(1)已知数据文件IN1.D ...

  4. 2012年信息系统项目管理师下半年上午考试习题与答案解析

    2012年下半年上午考试习题与答案解析 1.某信息系统项目采用原型法开发,以下做法中不正确的是(1) A.前期花足够的时间与客户充分沟通,完全明确需求后再开发实现 B.系统分析.设计和实现工作之间不做 ...

  5. 可视计算机应用期末考试,职称计算机考试photoshop考试习题复习

    职称计算机考试photoshop考试习题复习 导语:photoshop是一个功能强大的应用软件,下面是小编给大家提供的职称计算机考试photoshop考试习题复习,大家可以参考练习,更多习题练习请关注 ...

  6. CKA考试习题:存储管理-普通卷、PV、PVC

    所有命令都验证过,有更好的方式,欢迎留言~~~ CKA 习题和真题汇总 CKA考试经验:报考和考纲 CKA :2019年12月英文原题和分值 CKA考试习题:K8S基础概念--API 对象 CKA考试 ...

  7. 操作系统期末习题考试习题解答题目一

    操作系统期末习题考试习题解答题目一 目录 操作系统期末习题考试习题解答题目一 第一章 第二章 第三章 第一章 1.什么是操作系统的基本功能? 答:操作系统的职能是管理和控制计算机系统中的所有硬.软件资 ...

  8. 计算机电路基础综合题,计算机电路基础作业考试习题.doc

    计算机电路基础作业考试习题.doc (13页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 19.90 积分 一.简答题(6小题)1.共射极放大电路如图1 ...

  9. CKA考试习题:安全管理--Network Policy、serviceaccount、clusterrole

    所有命令都验证过,有更好的方式,欢迎留言~~~ CKA 习题和真题汇总 CKA考试经验:报考和考纲 CKA :2019年12月英文原题和分值 CKA考试习题:K8S基础概念--API 对象 CKA考试 ...

  10. 操作系统期末习题考试习题解答题目二

    操作系统期末习题考试习题解答题目二 目录 操作系统期末习题考试习题解答题目二 第四章 第五章 第六章 第四章 1.什么是分级调度?分时系统中有作业调度的概念吗?如果没有,为什么? P86 答:处理机调 ...

最新文章

  1. 习题2.5 两个有序链表序列的合并 (15 分)
  2. mysql语句将日期转换为时间戳的方法
  3. powershell自动化操作AD域、Exchange邮箱系列(5)——AD模块加载与命令一览
  4. Cacti 监控平台搭建
  5. MS-SQL数据类型详解
  6. 函数重载与函数覆盖的区别(C++)
  7. 在Latex如何添加Visio绘图
  8. ABOUT DOTA
  9. 仿新浪微博发布时 @ 及 #某话题# 的效果
  10. Scale-Equalizing Pyramid Convolution for Object Detection论文阅读
  11. 版本管理-SVN分支,合并,切换
  12. 利用网络信息减少因果推断中的confounding bias--结合两种思路的新方法
  13. HAUE河工计院OJ1100 - 1150题解
  14. Win7系统下搭建NFS服务器
  15. iOS基于MVC的项目重构总结
  16. 开心网首次起诉千橡 称山寨做法为不正当竞争
  17. 统一安全管理平台解决方案
  18. 【英语总结】11月英语
  19. 抖音直播短视频运营带货创业项目营销策划方案计划书
  20. HTML简单学习记录

热门文章

  1. CCS安装教程——学习DSP的第一步
  2. 初级工程师该如何去学习,如何去研发开关电源?
  3. 手机摄像头的组成结构和工作原理
  4. Bolt界面引擎QuickStart: SDK,教程和开发环境
  5. 2019年5月的Flag!
  6. Linux内存管理宏观篇(五)物理内存:页面分配和释放页面
  7. 虚拟服务器内存性能指标,vSphere 虚拟环境中超额配置 CPU、 内存和存储的比例推荐及规划简述...
  8. 数据挖掘概念与技术——读书笔记(7)
  9. Oracle下载及安装超详细教程
  10. vfp中写入文本文件_VFP中操作多种文件