版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 考试大纲 第一部分:Java语言基础 第二部分:流程控制 第三部分:面向对象 封装,继承,多态 第四部分:异常处理 第五部分:多线程 第六部分:Java 垃圾回收机制 第七部分:Java I/O 第八部分:Java集合和泛型 第九部分:Java SE实用APIQUESTION 1 Given the code in the exhibit. What is the result? A. Compilation fails B. An exception is thrown at runtime. C. An instance of Forest is serialized. D. An in
2、stance of Forest and an instance of Tree are both serialized.Answer: ( B )执行时期会抛出java.io.NotSerializableExcetpion异常。Tree必须实现Serialized接口;因为Forest实现了序列化,并且引用了Tree,但是Tree没有实现序列化!当一个实现序列化的类在类体里调用另外一个类的时候,那么另外一个类也要实现序列化!如果没有实现,则会报出运行时异常! 如果要实现序列化,他的成员变量也必须实现序列化.本题中Tree没有实现序列化,所以会产生java.io.NotSerializabl
3、eException的运行异常!参考大纲:IO操作 对象的序列化序列化的过程就是对象写入字节流和从字节流中读取对象。见SCJP.u1. SerializableTestQUESTION 2 Which code, inserted at line 14, will allow this class to correctly serialized and desterilized? A. s.defaultReadObject (); B. this = s.defaultReadObject (); C. y = s.default (); x = s.readInt (); D. x = s
4、.readInt(); y = s.readInt ();Answer: ( D )在反序列化方法中,从s对象中读取两个整数. 序列化是写对象,反序列化是读对象参考大纲:IO操作 对象的序列化QUESTION 3 Given the exhibit. What is the result? A. 0 B. 1 C. 4 D. Compilation fails E. An exception is thrown at runtime Answer: ( D ) 产生illegal escape character 非法转意符 的编译错误split()字符切割器本题是想用空格来分割字符串,只能用
5、“ ”或者“ s”来分割,“ s”没有这个转意字符!所以会报编译错误 tab可以用“ t”; “”可以用”表示.String的split方法用来分割字符串,这个方法接受一个正则表达式,根据表达式来分割,“s”表示空格,“s”没有这个转意字符,所以会产illegal escape character的编译错误。参考大纲:实用API String的split()方法和正则表达式QUESTION 4 Given the exhibit: The variable df is an object of type DateFormat that has been initialized in line
6、11. What is the result if this code is run on December 14,2000? A. The value of S is 14 - dic-2004 B. The value of S is Dec 14, 2000 C. An exception is thrown at runtime D. Compilation fails because of an error in line 13.Answer: ( D )DateFormat用来格式日期,它放在java.text包里,它没有setLocale方法,Local.Ialy 应该为 Loc
7、ale.ITALY. 代码语法有问题,编译错误!参考大纲:实用API java.util包 和java.text包 QUESTION 5 The doesFileExist method takes an array of directory names representing a path from the root filesystem and a file name. The method returns true if the file exists, false if does not.Place the code fragments in position to complete
8、 this method.Answer: ( )public static boolean doesFileExist(String directories, String filename) String path = ;for (String dir : directories) path = path + File.separator + dir;File file = new File(path, filename);return file.exists();参考大纲:IO操作 FileQUESTION 6Given: System.out.printf(Pi is approxima
9、tely %f and E is approximately %b, Math.PI, Math.E); Place the values where they would appear in the output.Answer: ( )3.True -判断E是否是NULL,NULL是FALSE 否则是TRUE.Pi=3.E=2.Printf() 是C中常用的语法;% f 表示浮点数(小数点后6位) , %b 表示boolean, %d表示整数.%e 十进制的科学计数法表示浮点数%a 16进制表示浮点型科学计数法的整数部分,以10进制表示指数%0 以8进制表示整数%x 以16进制表示整数%s
10、字符串个数输出%c char型格式输出 ,提供的值应为整数型%t 输出日期时间的前置 ?参考大纲:实用API Formatter 格式化输出工具QUESTION 7 When comparing java. io. BufferedWriter to java.io.FileWriter, which capability exist as a method in only one of the two? A. closing the stream B. flushing the stream C. writing to the stream D. marking a location in
11、the stream E. writing a line separator to the stream Answer: ( E )只有BufferedWriter具有newLine( )方法; Reader 才有mark功能。参考大纲:I/O操作 BufferWriter和FileWriterQUESTION 8 Given the exhibit: Which two code fragments, inserted independently at line 3, generate the output 4247? (choose two) A. String s = ;s. = (s-
12、123).replace (1,3, 24) - 89; /String 中只有”+”表示连接,但是无”-”;产生poerator-can not be applied to java.lang.String的编译错误B. StringBuffer s = new StringBuffer (); s.delete (0,3) .replace(1,3,24). delete (4,6); /delete(0,3)表示从0下标开始删除到3下标以前C. StringBuffer s = new StringBuffer (); s.substring (3,6).delete(1,3). ins
13、ert (1, 24). Substring()回传的是一个String而不是StringBuffer,String没有delete方法,产生cannot find symbol的编译错误D. StringBuilder s = new StringBuilder (); s.substring (3,6) delete (1,2). insert (1, 24) 错误同上E. StringBuilder s = new StringBuilder (); s.delete (0,3) replace(1,3,”). delete (2,5). insert (1, 24)Answer: (
14、B, E )A, String没有“-” 运算符; String不能修改!B, 正确 4247C, S.substring返回的是String, String没有delete()方法D, S.substring返回的是StringE, 正确 4247参考大纲:实用API String、StringBuffer线程安全的适用于多线程、StringBuilder线程不安全,适合单线程,但是性能高.StringBuffer StringBuilder的用法一样QUESTION 9Answer: ( B, D, E )A 错误,聚合中的对象实现了serializable就能被序列化 一个类包含另外一个
15、类就是聚合.A的描述和对象是否支持序列化没有直接关系B 正确 java是跨平台的,序列化的工作也统一交给各个平台的jvm来处理C 错误,不是volatile而是transient; 有这个transient瞬态关键字的话,就不能序列化了! Volatile这个修饰符的变量,实现的和多线程同步的方法类似,但是不是很好用!D 正确 transient 瞬态的对象是不支持序列化的E 正确,只要子类实现serializable, 不用考虑父类有无实现serializable参考大纲:IO操作 对象的序列化QUESTION 10Given the exhibit:What is the result?
16、A. short Long B. SHORT LONG C. Compilation fails D. An exception is thrown at runtimeAnswer: ( C ) 向上就近原则.第20行的go(z)将会依序找go(int i), go(long l),go(float f), go(double d) 或go(Integer i)方法.但是并不会自动向上转型Long然后再呼叫go(Long n),这种依顺序向上找的特性只会发生在对应端基本资料型别的情况下,参考大纲:面向对象 重载; 实用API 自动封包、拆包QUESTION 11Given the exhib
17、it: * d is valid , non-null Date object * df is a valid, non-null DateFormat object set to the current local What outputs the current locals country name and the appropriate version of Ds date? A. Locale loc = Locale.getLocal ( ); System.out printIn (loc.getDisplayCountry ( ) B. Locale loc = Locale.
18、getDefault ( ); System.out printIn (loc.getDisplayCountry ( ) + +df. format (d) ); C. Locale loc = Locale.getLocal ( ); System.out printIn (loc.getDisplayCountry ( ) + +df. setDateFormat (d) ); D. Locale loc = Locale.getDefault ( ); System.out printIn (loc.getDisplayCountry ( ) + +df.seDateFormat (d
19、) );Answer: ( B )A Locale类没有getLocal()方法,编译错误B 正确C 错误Locale类没有getLocal( )方法 DateFormat没有setDateFormat( )方法,编译错误D DateFormat没有setDateFormat( )方法 编译错误参考大纲:实用API java.util包 和java.text包 QUESTION 12Given the exhibit: What is the result? A. Compilation fails. B. An exception is thrown at runtime C. The co
20、de executes and prints running D. The code executes and prints runningrunning E. The code executes and prints runningrunninigrunningAnswer: ( E )t.run()调用main主线程去执行2-4行的run(),就是一次普通的方法调用 ;t.start()表示起用thread线程负责去执行2-4行的run(); 把2-4行的代码改为:public void run()String threadName=Thread.currentThread().getNa
21、me();System.out.println(threadName+”:running”);这样就可以看出是谁调用了run()了,显示如下:main : runningmain : runningThread-o : running参考大纲:多线程QUESTION 13-仔细看看Exhibit:Which two are possible results? (choose two) A. 0,2,4,4,6,8,10,6, B. 0,2,4,6,8,10,2,4,C. 0,2,4,6,8,10,12,14, D. 0,0,2,2,4,4,6,6,8,8,10,10,12,12,14,14,
22、E. 0,2,4,6,8,10,12,14,0,2,4,6,8,10,12,14,Answer: ( A, C)A 第一个线程循环到第三遍使得x等于4,并执行完第8句后挂起(此时current也是4);第二个线程开始执行,执行完以后第一个线程接着执行最后一次循环,打印6C 两个线程依次执行参考大纲:多线程QUESTION 14Given the exhibit: Which statement is true? A. This code may throw an InterruptedException B. This code may throw an IllegalStateExcepio
23、n C. This code may throw a TimeOutException after ten minutes D. This code will not compile unless obj.wait ( ) is replaced with ( Thread) obj) .wait ( ) E. Reversing the order of obj.wait ( ) and obj. notify ( ) may vcause this method to complete normally Answer: ( A ) 首先编译通不过, 第5行:void waitForSign
24、al() throws InterruptedException.第6行:Object obj=new Object();obj=Thread.currentThread();第7行应该是:synchronized(obj);-在写wait()和notify()方法时,除了要写在synchronized区段,.还需要撰写InterruptedException异常的try-catch. 本题就算写了try-catch,也可能会在执行的时候产生current thread not owner的IllegalMonitorStateException 的异常.参考大纲:多线程 同步处理QUESTI
25、ON 15Given the exhibit: What can be a result?A. Compilation fails B. An exception is thrown at runtime C. The code executes and prints StartedComplete D. The code executes and prints StartedComplete0123 E. The code executes and prints Started0123CompleteAnswer: ( E )Join()方法使得某个线程加入到正在执行的线程(本题是main线
26、程)中,执行完该线程才继续执行main线程.本程序中第5行由main线程执行,6行因为下达了join(),所以mian的执行将被暂停,等t做完run()方法的全部工作之后,才论到main继续执行未完成的工作!参考大纲:多线程 QUESTION 16Which two code fragments will execute the method doStuff ( ) in a separate thread? (choose two) A. new Thread ( ) public void run ( ) doStuff ( ); ; B. new Thread ( ) public vo
27、id start ( ) doStuff ( ); ; C. new Thread ( ) public void run ( ) doStuff ( ); .run ( ); D. new Thread ( ) public void run ( ) doStuff ( ); .start ( ); E. new Thread (new Runable ( ) public void run ( ) doStuff ( ); ). run ( ) ; F. new Thread (new Runnable ( ) public void run ( ) doStuff ( ); ).star
28、t ( );Answer: ( D、F )D 匿名类别中复写run方法,并调用start()方法启动线程F 利用匿名实现runnable接口中的run方法,并调用start()启动线程参考大纲:多线程QUESTION 17Which three will compile and run without exception? (choose three) A. private synchronized object o; B. void go ( ) synchronized ( ) /* code here */ C. public synchronized void go ( ) /* co
29、de here */ D. private synchronized (this) void go ( ) /* code here */ E. void go ( ) synchronized (Object.class) /* code here */ F. void go ( ) synchronized (o) /* code here */ Answer: ( C, E, F )A 错误synchronized不可以成为属性/变量的修饰符B 错误synchronized ( )中的括号中要加入欲锁定的物件或类型 / synchronized(this)C 正确 利用synchroni
30、zed来修饰对象instance方法,锁定的物件将会是this,D 错误 修饰方法时,this不用特别在synchronized ()中指明E 正确 合法的 class literals synchronized /针对某个类同步F 正确 合法的 instance block synchronized /针对某个对象同步参考大纲:多线程 线程同步QUESTION 18Exhibit: What is the result? A. The code will deadlock B. The code may run with no output C. An exception is thrown
31、 at runtime D. The code may run with output 0 6 E. The code may run with output 2 0 6 4 F. The code may run with output 0 2 4 6Answer: ( F )情况1 run方法运行以后运行 再调用getResult();情况2先调用getResult(),挂起,等待run()方法修改isComplete的值线程0, 线程1, 线程2, 线程3, main 共有5个线程,中间线程执行的顺序如上面所说的,但是最后的结果是main的for(Computation c: compu
32、tations)决定的,所以结果总是0 2 4 6参考大纲:多线程QUESTION 19Given the exhibit: What is the result? A. Compilation fails B. An exception is thrown at runtime C. The code executes normally and prints sleep D. The code executes normally, but nothing is printed.Answer: ( C ) 执行2行的时候main被放到Blocked中,过3秒后才会回到Runnable pool
33、中,继续执行输出”sleep”参考大纲:多线程QUESTION 20Which two statements are true about has-a and is-a relationships? (choose two) A. Inheritance represents an is -a relationship B. Inheritance represents a has-a relationship C. Interfaces must be used when creating a has-a relationship D. Instance variables can be u
34、sed when creating a has-a relationshipAnswer: ( A, D )Is-a:继承 class A extends B is-a ”是一个”,属于上下的关系,Has-a:聚合 class A B b; has-a “ 有一个” 属于聚合的关系,在java中用来表示类中的成员变量参考大纲:面向对象QUESTION 21Given the exhibit: What can directly access and change the value of the variable name? A. any class B. only the Target cl
35、ass C. any class in the Certkiller package D. any class that extends TargetAnswer: ( C )要修改name,必须先取得Target的对象,Target的存取权限是default,因此同一个包才能访问。参考大纲:面向对象 package与importQUESTION 22Which three statements are true? (choose three) A. A final method in class X can be abstract if and only if X is abstract B
36、. A protected method in class X can be overridden by any subclass of X. C. A private static method can be called only within other static methods in class X. D. A non-static public final method in class X can be overridden in any subclass of X.E. A public static method in class X can be called by a
37、subclass of X without explicitly referencing the class X. F. A method with the same signature as a private final method in class X can be implemented in a subclass of X.Answer: ( B,E,F )A 错误 抽象方法必须被实现,因此是不能加final修饰符的B 正确 子类可以合法的复写父类的protected权限的方法C 错误 private static方法在X类中的方法都可以调用,static 和non-static都
38、可以D 错误 final方法不可以复写,除非是private方法.但是这种情况不叫改写,而是子类有和父类一样的private final方法,两个方法是各自独立的!E 正确 不用加上父类别的引用,子类就可以直接调用父类的static方法F 正确 父类的private static方法和子类中同名private static方法是两个独立方法,这种情况就不叫改写,而是各自拥有自己的方法!参考大纲:面向对象QUESTION 23Place the Types in one of the Type columns, and the Relationships in the Relationship
39、column, to define appropriate has-a and is-a relationships.Answer: ( )Dog is-a Animal 是一类Forest has-a Tree 有一个Rectangle has-a Square 矩形有一个正方形Java Book is-a Programming Book 是一个参考大纲:面向对象QUESTION 24Replace two of the Modifiers that appear in the Single class to make the code compile. Note: Three modif
40、iers will not be used and four modifiers in the code will remain unchanged.Answer: ( )public class Singleprivate static Single instance;public static Single getInstance()if(instance=null) instatnce = create();return instance;protected Single() 因为SingleSub继承了Single,所以Single的构造器必须可以让子类访问到!static Singl
41、e Create()return new Single(); 因为第4行=create();说明这个方法必须是static的方法参考大纲:static成员和继承时方法的权限控制QUESTION 25Exhibit: What is the result?A. Value is : 8 B. Compilation fails. C. Value is : 12 D. Value is ; -12 E. The code runs with no output F. An exception is thrown at runtime.Answer: ( A )2行,value默认是=0;9行实例
42、化一个MultiCale对象,并传了一个参数multiplier=2,10行调用3行的方法;方法内的calculate()又调用2行,结果value=0-3;然后super.calculate()调用父类的calculate(),value=-3+7=4;然后6行,value=value*multiplier=4*2=8;然后到11行,输出value is : 8参考大纲:面向对象QUESTION 26Given the exhibit: Which statement is true? A. The class is fully encapsulated B. The code demons
43、trates polymorphism. C. The ownerName variable breaks encapsulation D. The CardID and limit variables break polymorphism E. The setCardInformation method breaks encapsulationAnswer: ( C )第24行破坏了封装,应该成private String ownerName;参考大纲:面向对象 封装QUESTION 27Given the exhibit: What is the result? A. peep B. ba
44、rk C. moveD. Compilation fails. E. An exception is thrown at runtimeAnswer: ( E )31行运行时发生造型异常,运行时错误!30行后Animal的实体是dog,31行有转型到cat是不对的(兄弟类之间不能转换)!编译是没有错误是因为dog 和cat有共同的父类,参考大纲:面向对象 多态QUESTION 28-概念Exhibit: What two must the programmer do to correct the compilation errors? A. insert a call to this ( )
45、in the Car constructorB. insert a call to this ( ) in the MeGo constructor C. insert a call to super ( ) in the MeGo constructor D. insert a call to super (vin) in the MeGo constructorE. change the wheelCount variable in CAR TO PROTECTEDF. CHANGE LINE 3 IN THE MeGo class to super.wheelCount =3;Answe
46、r: ( D、E )D父类无默认构造函数,子类需显示调用父类的构造函数利用super(参数)来调用父类的构造函数E wheelCount为私有变量,子类无法访问,改成default,public protected都可以,本题改成protected比较合适2行改为 protected int wheelCount;And 2行和3行之间插入super(vin);参考大纲:面向对象QUESTION 29-多态Given the exhibit: polymorphism? (choose three) A. public void add (C c) c.getValue ( ); B. pub
47、lic void add (B b) b.getValue ( ); C. public void add (A a) a.getValue ( ); D. public void add (A a, B b) a.getValue ( ); E. public void add (C c1, C c2) c1.getValue ( ); Answer: ( B, C, D )A E 只是简单的使用C的方法多态必须存在继承参考大纲:面向对象 多态QUESTION 30Given the exhibit: Which statement should be placed at line 14 t
48、o suggest that the virtual machine expend effort toward recycling the memory used by the object Certkiller ? A. System.gc ( ) B. Runtime. Gc ( ) C. System.freeMemory ( ) D. Runtime.getRuntime ( ) .growHeap ( ) E. Runtime.getRuntime ( ) .freeMemory ( ) Answer: ( A )建议JVM进行资源回收的方法:System.gc();Runtime.
49、getRuntime().gc();参考大纲:面向对象 垃圾回收机制QUESTION 31Exhibit:What is the output of the program shown in the exhibit? A. 300.100.100.100.100 B. 300.300.100.100.100 C. 300.300.300.100.100 D. 300.300.300.300.100Answer: ( B )参考大纲:Java语言基础 对象的存储QUESTION 32A developer is creating a class Book, that needs to acces
50、s class Paper. The Paper class is deployed in a JAR named myLib.jar. Which three, taken independently, will allow the developer to use the Paper class while compiling the Book class? (choose three) A. The JAR file is located at $JAVA_HOME/jre/classes/myLib.jar B. The JAR file is located at $/JAVA_HO
51、ME/jre/lib/ext/myLib.jar. C. The JAR file is located at /foo/myLib.jar and a classpath environment variable is set that includes /foo/myLib.jar/Paper,Class. D. The JAR file is located at /foo/myLib.jar and a classpath environment variable is set that includes /foo/myLib.jar. E. The JAR file is locat
52、ed at /foo/myLib.jar and the Book class is compiled using javac -cp /foo/myLib.jar/Paper Book java. F. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac -d /foo/myLib.jar Book java.G. The JAR file is located at /foo/myLib.jar and the Book class is compiled using ja
53、vac -classpath /foo/myLib.jar Book.javaAnswer: ( B, D, G )Javac -d 指定编译后的文件存放的位置Javac cp 指定编译时需要用到的类文件位置参考大纲:Java语言基础 Classpath设定QUESTION 33Given the exhibit: Which statement is true about the object referenced by snoog, smooch 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 coll
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 兰州应急预案备案(3篇)
- epc管网施工方案(3篇)
- 2026年陕西省渭南市单招职业倾向性测试题库附答案详解(突破训练)
- 2026年闽西职业技术学院单招综合素质考试题库附答案详解(轻巧夺冠)
- 2026年陕西服装工程学院单招职业倾向性考试题库附参考答案详解ab卷
- 2026年鞍山职业技术学院单招职业适应性测试题库含答案详解(预热题)
- 2026年陕西艺术职业学院单招职业适应性测试题库附参考答案详解(研优卷)
- 2026年马鞍山师范高等专科学校单招职业技能考试题库及答案详解1套
- 2026年陕西工业职业技术学院单招职业倾向性考试题库附答案详解(突破训练)
- 2026年鹤壁职业技术学院单招职业技能考试题库附参考答案详解(巩固)
- 第6课第1课时呵护花季激扬青春【中职专用】《心理健康与职业生涯》(高教版2023基础模块)
- 道路绿化养护投标方案(技术方案)
- 品牌策划与推广(第3版 数字教材版) 课件全套 人大 第1-9章 品牌的本质及其定位决策-营销活动策划与管理
- 爆破作业人员教育培训制度
- 辊道窑作业标准指导书
- GB/T 24421.1-2023服务业组织标准化工作指南第1部分:总则
- 井巷用全自动全液压凿岩台车设计书
- 蚕桑产业建设汇报材料(四)
- 借调人员协议-三方协议
- 2022版化学检验工高级工考核题库(全真题库)
- DB11-T 1000.1-2020企业产品标准编写指南 第1部分:标准的结构和通用内容的编写
评论
0/150
提交评论