Java考试题之八
QUESTION 139
Giventhe following directory structure: bigProject |--source | |--Utils.java ||--classes |-- And the following command line invocation: javac -d classessource/Utils.java Assume the current directory is bigProject, what is theresult?
A. If the compile is successful, Utils.class is added to thesource directory.
B. The compiler returns an invalid flag error.
C. If the compile is successful, Utils.class is added to theclasses directory.
D. If the compile is successful, Utils.class is added to thebigProject directory.
Answer: C
Section: (none)
QUESTION 155
Given:
10. interface Data { public voidload(); }
11. abstract class Info { publicabstract void load(); }
Which class correctly uses the Datainterface and Info class?
A. public class Employee extendsInfo implements Data { public void load() { /*do something*/ }
}
B. public class Employeeimplements Info extends Data { public void load() { /*do something*/ }
}
C. public class Employee extendsInfo implements Data { public void load(){ /*do something*/ }public voidInfo.load(){ /*do something*/ }
}
D. public class Employeeimplements Info extends Data { public void Data.load(){ /*do something*/}public void load(){ /*do something*/ }
}
E. public class Employeeimplements Info extends Data { public void load(){ /*do something*/ }publicvoid Info.load(){ /*do something*/ }
}
F. public class Employee extendsInfo implements Data{public void Data.load() { /*do something*/ }
public void Info.load() { /*do something*/}
}
Answer: A
QUESTION 156 Given:
11. public class Rainbow {
12. public enum MyColor {
13. RED(0xff0000), GREEN(0x00ff00),BLUE(0x0000ff);
14. private final int rgb;
15. MyColor(int rgb) { this.rgb =rgb; }
16. public int getRGB() { returnrgb; }
17. };
18. public static voidmain(String[] args) {
19. // insert code here
20. }
21. }
Which code fragment, inserted at line 19,allows the Rainbow class to compile?
A. MyColor skyColor = BLUE;
B. MyColor treeColor =MyColor.GREEN;
C. if(RED.getRGB() <BLUE.getRGB()) { }
D. Compilation fails due to othererror(s) in the code.
E. MyColor purple = newMyColor(0xff00ff);
F. MyColor purple = MyColor.BLUE +MyColor.RED;
Answer: B枚举常量不能实例化,只能在定义的时候制定。
Section: (none)
QUESTION 157 Given:
10. class One {
11. void foo() { }
12. }
13. class Two extends One {
14. //insert method here
15. }
Which three methods, inserted individuallyat line 14, will correctly complete class Two? (Choose three.)
A. int foo() { /* more code here*/ }
B. void foo() {/* more code here */ }
C. public void foo(){ /* more code here */ }
D. private void foo() { /* morecode here */ }
E. protectedvoid foo() { /* more code here */ }
Answer: BCE
8pt;mso-list:l1 level1 lfo2'>B. MyColor treeColor =MyColor.GREEN;
C. if(RED.getRGB() <BLUE.getRGB()) { }
D. Compilation fails due to othererror(s) in the code.
E. MyColor purple = newMyColor(0xff00ff);
F. MyColor purple = MyColor.BLUE +MyColor.RED;
Answer: B
Section: (none)
Click the Exhibit button.
Which statement is true about the classes and interfaces in the exhibit?
A. Compilation will succeed for all classes and interfaces.
B. Compilation of class C will fail because of an error in line 2.
C. Compilation of class C will fail because of an error in line 6.
D. Compilation of class AImpl will fail because of an error in line 2.
Answer: C
考察多态性的动态绑定,如果方法的签名相同,则返回类型应该与超类的相同或是超类中返回类型的子类型。上题中C类中有方法Object execute() 以及 String execute(),Object不是Strng类型的子类型,所以错误。
QUESTION 159 Given:
11. public interface A { public void m1();}
12.
13. class B implements A { }
14. class C implements A { publicvoid m1() { } }
15. class Dimplements A { public void m1(int x) { } }
16. abstract class E implements A {}
17. abstract class F implements A {public void m1() { } }
18. abstractclass G implements A { public void m1(int x) { } }
What is the result?
A. Compilation succeeds.
B. Exactlyone class does NOT compile.
C. Exactly two classes do NOTcompile.
D. Exactly four classes do NOTcompile.
E. Exactly three classes do NOTcompile.
Answer: C
B类没有实现接口A,C类无错,D类没有实现函数void m1();~~abstract抽象类可以不去实现接口
QUESTION 160 Given:
1. class Alligator {
2. public static voidmain(String[] args) {
3. int []x[] = {{1,2}, {3,4,5},{6,7,8,9}};
4. int [][]y = x;
5. System.out.println(y[2][1]);
6. }
7. }
What is the result?
A. 2 B. 3 C. 4 D. 6 E. 7
F. Compilation fails.
Answer: E
Click the Exhibit button.
1. public class GoTest {
2. public static void main(String[] args) {
3. Sente a = new Sente(); a.Go();
4. Goban b = new Goban(); b.go();
5. Stone c = new Stone(); c.go();
6. }
7. }
8.
9. class Sente implements Go {
10. public void go() { System.out.println(”go in Sente.”); }
11. }
12.
13. class Goban extends Sente {
14. public void go() { System.out.println(”go in Goban”); }
15. }
16.
17. class Stone extends Goban implements Go { }
18.
19. interface Go { public void go(); }
What is the result?
A. go in Goban
go in Sente
go in Sente
B. go in Sente
go in Sente
go in Goban
C. go in Sente
go in Goban
go in Goban
D. go in Goban
go in Goban
go in Sente
E. Compilation fails because of an error in line 17.
Answer: C
QUESTION 162 Given:
12. NumberFormat nf =NumberFormat.getInstance();
13. nf.setMaximumFractionDigits(4);
14. nf.setMinimumFractionDigits(2);
15. String a =nf.format(3.1415926);
16. String b = nf.format(2);
Which two statements are true about theresult if the default locale is Locale.US? (Choose two.)
A. The value of b is 2.
B. The value of a is 3.14.
C. The value ofb is 2.00.
D. The value of a is 3.141.
E. The value of a is 3.1415.
F. F. The valueof a is 3.1416.
G. The value of b is 2.0000.
Answer: CF
setMaximumFractionDigits是设置小数点后的数字的最max个数~~
setMinimumFractionDigits是设置小数点后的数字的最min个数~~
setMinimumIntegerDigits是设置小数点前的数字的最min个数~~
QUESTION 163 Given:
11. String test ="a1b2c3";
12. String[] tokens =test.split("\\d");
13. for(String s: tokens)System.out.print(s + " ");
What is the result?
A. a b c
B. 1 2 3
C. a1b2c3
D. a1 b2 c3
E. Compilation fails.
F. The code runs with no output.
G. An exception is thrown atruntime.
Answer: A
.
d代表digital数字~~ 表示以数字进行拆分
QUESTION 164 Given:
11. class Converter {
12. public static voidmain(String[] args) {
13. Integer i = args[0];
14. int j = 12;
15. System.out.println("It is" + (j==i) + " that j==i.");
16. }
17. }
What is the result when the programmerattempts to compile the code and run it with the command java Converter 12?
A. It is true that j==i.
B. It is false that j==i.
C. An exception is thrown atruntime.
D. Compilation fails because of anerror in line 13.
Answer: D
Integer i = args[0];,无法将String类型的对象付给Integer,应该是13. Integer i = Integer.parseInt( args[0]);
QUESTION 165 Given:
1. public class BuildStuff {
2. public static voidmain(String[] args) {
3. Boolean test = newBoolean(true);
4. Integer x = 343;
5. Integer y = newBuildStuff().go(test, x);
6. System.out.println(y);
7. }
8. int go(Boolean b, int i) {
9. if(b) return (i/7);
10. return (i/49);
11. }
12. }
What is the result?
A. 7
B. 49
C. 343
D. Compilation fails.
E. An exception is thrown atruntime.
Answer: B b为true,执行第九行,343/7 是 49~~
QUESTION 166 Given:
12. String csv ="Sue,5,true,3";
13. Scanner scanner = new Scanner(csv );
14. scanner.useDelimiter(",");
15. int age = scanner.nextInt();
What is the result?
A. Compilation fails.
B. After line 15, the value of ageis 5.C. After line 15, the value of age is 3.
D. An exception is thrown at runtime.
Answer: D
下一个读取的是sue,String类型;
String csv="sue,5,true,3";
Scanner scanner=new Scanner(csv); scanner.useDelimiter(","); String s=scanner.next(); System.out.println(s);
QUESTION 167
Given:
1. import java.util.*;
2. public class WrappedString {
3. private String s;
4. public WrappedString(String s) { this.s = s; }
5. public static void main(String[] args) {
6. HashSet<Object> hs = new HashSet<Object>();
7. WrappedString ws1 = new WrappedString("aardvark");
8. WrappedString ws2 = new WrappedString("aardvark");
9. String s1 = new String("aardvark");
10. String s2 = new String("aardvark");
11. hs.add(ws1); hs.add(ws2); hs.add(s1); hs.add(s2);
12. System.out.println(hs.size()); } }
What is the result?
A. 0
B. 1
C. 2
D. 3
E. 4
F. Compilation fails.
G. An exception is thrown at runtime.
Answer: D
WrappedString 的hashCode()是继承自Object类,而String的hashCode()时重写过的仅与字符串的内容有关。ws1 和ws2存储地址不同,所以hashCode()的返回值不同,而s1和s2字符串的内容相同,哈希值相同。
QUESTION 168
Given a class whose instances, when found in a collection of objects, are sorted by using the compareTo()
method, which two statements are true? (Choose two.)
A. The class implements java.lang.Comparable.
B. The class implements java.util.Comparator.
C. The interface used to implement sorting allows this class to define only one sort sequence.
D. The interface used to implement
QUESTION 169
Given:
1. import java.util.*;
2. public class Example {
3. public static void main(String[] args) {
4. // insert code here
5. set.add(new Integer(2));
6. set.add(new Integer(1));
7. System.out.println(set);
8. }
9. }
Which code, inserted at line 4, guarantees that this program will output [1, 2]?
A. Set set = new TreeSet();
B. Set set = new HashSet();
C. Set set = new SortedSet();
D. List set = new SortedList();
E. Set set = new LinkedHashSet();
Answer: A
必须是排好序的集合,所以TreeSet合适。
而HashSet应该也可以的,Integer类型的hashCode()函数返回的是相应的int类型的值。如果就只有一个答案的话TreeSet是最好的选项。
SortedSet是一个interface,java里面没有SortedList类。
170. public class Person {
12. private name;
13. public Person(String name) {
14. this.name = name;
15. }
16. public int hashCode() {
17. return 420;
18. }
19.
}
Which statement is true?
A. The time to find the value from HashMap with a Person key depends on the
size of the map.
B. Deleting a Person key from a HashMap will delete all map entries for all keys of type Person.
C. Inserting a second Person object into a HashSet will cause the first Person object to be
removed as a duplicate.
D. The time to determine whether a Person object is contained in a HashSet is constant and does NOT
depend on the size of the map.
Answer: A
B选项:删除HashMap中一个Person对象对应的键将会删除这个散列映射表中Person类的全部条目。错误,HashMap中Person对象的键值不是由Person对象决定的,而是程序员给定的键,例如staff.add("123-345", bob),就是把键为123-456的bob对象添加到名为staff的HashMap中,因而HashMap允许添加相同的对象。所以说,删除一个键对应的Person对象并不会删除所有的条目,他们的key都不同嘛。
C选项:向HashSet中插入另外一个Person对象将会引起第二个对象覆盖第一个对象。错误,虽然Person对象的hashCode方法返回的值都是420,这仅仅表明两个Person对象在一个entry链表中,接下来要调用equals方法,由于Person类没有equals方法,所以调用Object的equals方法返回对象的存储地址,很明显两个Person对象的存储地址是不同的。综上,HashSet中可以添加不同的Person对象,只要equals方法返回值为false就好。
D选项:判断一个HashSet中是否存在一个Person对象的次数是常数次,和map的大小无关。错误,由于Person对象的hashCode返回的值都是420,所以HashSet中的Person对象都在一个bucket中,组成了一条entry链表,查询速度与entry链表的大小息息相关。
A:选项:由key来查找value的次数与map的大小有关。正确,map越大,即bucket的个数越多,entry链的长度相应的来说就越小(hashcode和桶个数取余后的数一样的几率就越小)。
Java考试题之八的更多相关文章
- java设计模式之八代理模式(Proxy)
其实每个模式名称就表明了该模式的作用,代理模式就是多一个代理类出来,替原对象进行一些操作,比如我们在租房子的时候回去找中介,为什么呢?因为你对该地区房屋的信息掌握的不够全面,希望找一个更熟悉的人去帮你 ...
- java 入门之八大内置基本类型
本文采用eclipse 工具演示,如果您对eclipse 工具不了解,请先学习下 eclipse 工具的使用,这个里面只是简单的介绍下输出和注释: 安装完成eclipse 以后,双击进入 后一次点击 ...
- 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 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 ...
- Java考试题之三
QUESTION 46Given:11. public class Test {12. public static void main(String [] args) {13. int x = 5;1 ...
- Java考试题
1. public class GC { 2. private Object o; 3. private voiddoSomethingElse(Object obj) { o ...
随机推荐
- docker私服搭建nexus3
docker私服搭建有官方的registry镜像,也有改版后的NexusOss3.x,因为maven的原因搭建了nexus,所以一并将docker私服也搭建到nexus上. nexus的安装过程就单独 ...
- Netty源码分析第1章(Netty启动流程)---->第4节: 注册多路复用
Netty源码分析第一章:Netty启动流程 第四节:注册多路复用 回顾下以上的小节, 我们知道了channel的的创建和初始化过程, 那么channel是如何注册到selector中的呢?我们继 ...
- AtCoder | ARC102 | 瞎讲报告
目录 ARC102 前言 正文 传送链接~ ARC102 前言 实在是太菜了....写完第一题就弃疗..感觉T3好歹也是道可做题吧!!然后T2怎么又是进制拆分! 正文 A 题意 给你两个数字\(n,k ...
- JavaScript学习(1)之JavaScript基础
JavaScript学习(1)之JavaScript基础 由于工作原因,开发语言逐渐以JavaScript为主,所以,抽空学习了下JavaScript语法.等现阶段的工作稳定之后,陆续会分享下自己在学 ...
- jsweb常用代码
<script> $(function (){ $.ajax({ url: 'https://test.com:8080/api/v1/users?query_not_auth=100&a ...
- final文案+美工展示
作业要求:https://edu.cnblogs.com/campus/nenu/SWE2017FALL/homework/1438 团队介绍:thunder 组成员及各位博客地址: 1.王航:htt ...
- Daily Scrumming* 2015.10.29(Day 10)
一.总体情况总结 二.今明两天任务表 Member Today’s Task Tomorrow’s Task 江昊 了解微信API,与社团服务平台创业公司嗨社团创始人沟通,了解其平台运营方案与商业模式 ...
- 暑假作业app博客
一.光照传感器 界面 简介 运用了传感器类,通过手机的感应区根据当时的光照强度显示出数据. 核心代码 protected void onCreate(Bundle savedInstanceState ...
- 2017-2018-2 1723 『Java程序设计』课程 结对编程练习-四则运算-准备阶段
2017-2018-2 1723 『Java程序设计』课程 结对编程练习-四则运算-准备阶段 在一个人孤身奋斗了将近半个学期以后,终于迎来的我们的第一次团队协作共同编码,也就是,我们的第一个结对编程练 ...
- WebGL学习笔记三
在上一章中主要说明了通过矩阵来实现平面图形的平移.旋转.缩放,到最后完全可以用4*4矩阵实现所有的动作,在本章就是第四章主要是对矩阵进行了封装,其WebGL的流程和上一章大部分大部分相同,定义可以在w ...