ImageVerifierCode 换一换
格式:DOC , 页数:145 ,大小:207.54KB ,
资源ID:8406894      下载积分:20 金币
快捷注册下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

开通VIP
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.zixin.com.cn/docdown/8406894.html】到电脑端继续下载(重复下载【60天内】不扣币)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

开通VIP折扣优惠下载文档

            查看会员权益                  [ 下载后找不到文档?]

填表反馈(24小时):  下载求助     关注领币    退款申请

开具发票请登录PC端进行申请

   平台协调中心        【在线客服】        免费申请共赢上传

权利声明

1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。

注意事项

本文(2024年ocjp考试题库.doc)为本站上传会员【快乐****生活】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4009-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

2024年ocjp考试题库.doc

1、1. Given: 1. public class returnIt { 2. returnType methodA(byte x, double y){ 3. return (short) x/y * 2; 4. } 5. } What is the valid returnType for methodA in line 2? A. int B. byte C. long D. short E. float F. double Answer F 注释:short类型的x,除以double类型的y,

2、再乘int的2,因此成果是double类型的。注意第三行的强制转换,只是转换了x。 2. 1) class Super{ 2) public float getNum(){return 3.0f;} 3) } 4) 5) public class Sub extends Super{ 6) 7) } which method, placed at line 6, will cause a compiler error? A. public float getNum(){return 4.0f;} B. public void getNum(){}

3、C. public void getNum(double d){} D. public double getNum(float d){return 4.0d;} Answer :B 注意这道题重要考的是措施的overload和override。对于overload,只有参数列表不一样,才做为标准,而返回值和访问控制核心字不能做为标准,因此B错在措施名相同,但只有返回值不一样,这是错的。C和D是正确的overload。对于override,则访问控制核心字只能愈加公有化,异常只能是超类措施抛出的异常的子类,也能够不抛出。返回类型,参数列表必须精准匹配。因此A是正确的overrid

4、e。 3. 1)public class Foo{ 2) public static void main(String args[]){ 3) try{return;} 4) finally{ System.out.println("Finally");} 5) } 6) } what is the result? A. The program runs and prints nothing. B. The program runs and prints “Finally”. C. The code compiles,

5、but an exception is thrown at runtime. D. The code will not compile because the catch block is missing. Answer:b try......catch......finally的问题。程序中假如遇到return,则finally块先被执行,然后再执行retrun,而finally块背面的语句将不被执行。假如遇到System.exit(1),则finally块及其后的语句都不执行,整个程序退出,还执行什么呀。 4. 1) public class Test{ 2)

6、public static String output=""; 3) public static void foo(int i){ 4) try { 5) if(i==1){ 6) throw new Exception(); 7) } 8) output +="1"; 9) } 10) catch(Exception e){ 11) output+="2"; 12)

7、 return; 13) } 14) finally{ 15) output+="3"; 16) } 17) output+="4"; 18) } 19) public static void main(String args[]){ 20) foo(0); 21) foo(1); 22) 23) } 24) } what is the value of outp

8、ut at line 22? Asnwer:13423 执行第一个foo(0)时,执行第8条语句,output=1,然后执行语句15,output=13,然后是17条,output=134,因为是static类型的变量,因此任何对其值的修改都有效。执行第二条foo(1),先执行语句5,成果抛出异常,转到catch块,output=1342,finally任何情况下都执行,因此output=13423,然后return跳出措施体,因此output=13423 5. 1)public class IfElse{ 2)public static void main(Str

9、ing args[]){ 3)if(odd(5)) 4)System.out.println("odd"); 5)else 6)System.out.println("even"); 7)} 8)public static int odd(int x){return x%2;} 9)} what is output? Answer: 编译错误。 if中的判断条件的成果必须是boolean类型的。注意这里说的是成果. 6.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 1)class ExceptionTes

10、t{ 2)public static void main(String args[]){ 3)try{ 4)methodA(); 5)}catch(IOException e){ 6)System.out.println("caught IOException"); 7)}catch(Exception e){ 8)System.out.println("caught Exception"); 9) } 10) } 11)} If methodA() throws a IOException, what is the result? Ans

11、wer: caught IOException 假如methodA()抛出IOExecption,被语句6捕捉,输出caught IOException,然后呢??然后就结束了呗。 7. 1)int i=1,j=10; 2)do{ 3) if(i++>--j) continue; 4)}while(i<5); After Execution, what are the value for i and j? A. i=6 j=5 B. i=5 j=5 C. i=6 j=4 D. i=5 j=6 E. i=6 j=6 Answer

12、 d 程序一直循环,直到i=4,j=6时,执行完语句3后,i会++,这时i就等于了5,continue后就不能再循环了,因此选D。 8. 1)public class X{ 2) public Object m(){ 3) Object o=new Float(3.14F); 4) Object[] oa=new Object[1]; 5) oa[0]=o; 6) o

13、null; 7) oa[0]=null; 8) System.out.println(oa[0]); 9) } 10) } which line is the earliest point the object a refered is definitely elibile to be garbage collectioned? A.After line 4

14、 B. After line 5 C.After line 6 D.After line 7 E.After line 9(that is,as the method returns) Answer: d 当执行第6行后,仍然有对象指向o,因此o不能满足条件,当第7条语句被执行后,就再也没有对象指向o了,因此选D。 9.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 1) interface Foo{ 2) int k=0; 3) } 4) public

15、class Test implements Foo{ 5) public static void main(String args[]){ 6) int i; 7) Test test =new Test(); 8) i=test.k; 9) i=Test.k; 10)

16、 i=Foo.k; 11) } 12) } What is the result? A. Compilation succeeds. B. An error at line 2 causes compilation to fail. C. An error at line 9 causes compilation to fail. D. An error at line 10 causes compilation to fail. E. An error at line 11 causes compilatio

17、n to fail. Answer: A 编译通过,通过测试的 10. what is reserved(保存) words in java? A. run B. default C. implement D. import Answer: b,D 11. 1)public class Test{ 2) public static void main(String[] args){ 3) String foo=args[1]; 4) Sring bar=args[2]; 5) String baz=args[3]; 6)

18、} 7) } java Test Red Green Blue what is the value of baz? A. baz has value of "" B. baz has value of null C. baz has value of "Red" D. baz has value of "Blue" E. baz has value of "Green" F. the code does not compile G. the program throw an exception Answer: G 当执行java

19、 Test Red Green Blue时,数组args只有[0][1][2],运行时ArrayIndexOutOfBoundsException这个异常会被抛出,数组越界。 12. int index=1; int foo[]=new int[3]; int bar=foo[index]; int baz=bar+index; what is the result? A. baz has a value of 0 B. baz has value of 1 C. baz has value of 2 D. an exception is thrown

20、E. the code will not compile Answer: b 数组初始化后默认值是0,因此baz=0+1=1 13. which three are valid declaraction(行为) of a float? A. float foo= -1; B. float foo=1.0; C. float foo=42e1; D. float foo=2.02f; E. float foo=3.03d; F. float foo=0x0123; Answer: A,D,F 其他的系统都会以为是double类型,

21、因此犯错。说一下A和C的区分吧,-1系统会以为是一个int类型,把int类型再赋给float类型的foo,当然没错了,可C就不一样啦,42e1是int类型吗?? 14. 1)public class Foo{ 2) public static void main(String args[]){ 3) String s; 4) System.out.println("s="+s); 5) } 6) } what is the result? A. The code compiles and “s=” is printed. B. The code compil

22、es and “s=null” is printed. C. The code does not compile because string s is not initialized(初始化). D. The code does not compile because string s cannot be referenced(引用). E. The code compiles, but a NullPointerException is thrown when toString is called. Answer:C 只有实例变量系统才予以自动赋默认值的这种待遇

23、15. 1) public class Test{ 2) public static void main(String args[]){ 3) int i=oxFFFFFFF1; 4) int j=~i; 5) 6) } 7) } which is decimal value of j at line 5? A. 0 B.1 C.14 D.-15 E. compile error at line 3 F. compile error at line 4 Answer: C 算一

24、算就懂得了。 16. float f=4.2F; Float g=new Float(4.2F); Double d=new Double(4.2); Which are true? A. f==g B. g==g C. d==f D. d.equals(f) E d.equals(g) F. g.equals(4.2); Answer: B ==两边类型不一样不相等。因此A和C不等。equals只能用于引用类型,不能用于基本类型,因此D不对,并且两边类型不兼容的话,虽然对象的内容同样,也不相等,因此E和F不对。 17.

25、@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 1)public class Test{ 2) public static void add3(Integer i){ 3) int val=i.intValue(); 4) val+=3; 5) i=new Integer(val); 6) } 7) public static void main(String args[]){ 8) Integer i=new Integer(0); 9) add3(i); 10)

26、 System.out.println(i.intValue()); 11) } 12)} what is the result? A. compile fail B.print out "0" C.print out "3" D.compile succeded but exception at line 3 Answer: b 在第五行里,程序又操作了New,重新分派了内存空间。因此此i非彼i啦。 18. 1)public class Test{ 2) public static void main(S

27、tring[] args){ 3) System.out.println(6^3); //‘^’为XOR 4) } 5) } what is output? Answer: 5算呗。 19. 1) public class Test{ 2) public static void stringReplace(String text){ 3) text=text.replace('j','l'); 4) } 5) public static void bufferReplace(StringBuffer text){ 6)

28、 text=text.append("c"); 7) } 8) public static void main(String args[]){ 9) String textString=new String("java"); 10) StringBuffer textBuffer=new StringBuffer("java"); 11) StringReplace(textString); 12) bufferReplace(textBuffer); 13) System.out.println(textString+textBuffe

29、r); 14) } 15) } what is the output? Answer: javajavac textString是String类型的,具备不变性,语句3其实是创建了一个新的字符串,而不是修改本来的textString,而对于StringBuffer类型的对象,则所有修改都是实在的。因此在语句6中textBuffer变成了javac,因此输出为javajavac。 20. 1)public class ConstOver{ 2) public ConstOver(int x, int y, int z){} 3) }

30、which two overload the ConstOver constructor? A.ConstOver(){} B.protected int ConstOver(){} C.private ConstOver(int z, int y, byte x){} D.public void ConstOver(byte x, byte y, byte z){} E.public Object ConstOver(int x, int y, int z){} Answer: a,c 重要的问题是overload,参数列表必须不一样,措施名相同,访

31、问控制无限制。也无异常限制。这道题因为是结构器,因此B,D和E不对,因为结构器不能有返回类型。 21. 1)public class MethodOver{ 2) public void setVar(int a, int b, float c){} 3) } which overload the setVar? A.private void setVar(int a, float c, int b){} B.protected void setVar(int a, int b, float c){} C.public int setVar(int a, f

32、loat c, int b){return a;} D.public int setVar(int a, float c){return a;} Answer: a,c,d overload无访问控制限制,因此A对,次序也属于参数列表,次序不一样也同样是overload,因此C正确,D当然正确了,参数列表白显不一样。 22.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 1)class EnclosingOne{ 2)public class InsideOne{} 3) } 4)public class InnerTest{

33、 5) public static void main(String args[]){ 6) EnclosingOne eo=new EnclosingOne(); 7) //insert code here 8) } 9)} A.InsideOne ei=eo.new InsideOne(); B.eo.InsideOne ei=eo.new InsideOne(); C.InsideOne ei=EnclosingOne.new InsideOne(); D.InsideOne ei=eo.new InsideOne(); E.EnclosingOne

34、InsideOne ei=eo.new InsideOne(); Answer: e 这里边的某些形式是固定的。 (1)静态措施访问非静态内类: 措施为: Outer myouter=new Outer();//这里的myouter是创建的外部类的对象。 Outer.Inner myinner=myouter.new Inner();//myinner是内类的对象。 然后再myinner.showName();//showName()是外类中的非静态措施。 (2)非静态措施访问非静态内

35、类 直接创建该内部类的对象:new Inner().showName(); (3)静态措施访问静态内类: 也是直接创建该内部类的对象,即Inner myinner = new Inner(),或者Outer.Inner myinner = new Outer.Inner()也行得通哦。 23. What is "is a" relation? A.public interface Color{} public class Shape{private Color color;} B.in

36、terface Component{} class Container implements Component{ private Component[] children; } C.public class Species{} public class Animal{private Species species;} Answer: b "is a "意思为是什么:定义了一个超类和一个子类之间的一个直接关系:子类是超类的一个。也即是继承的关系 24.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 1

37、)package foo; 2) 3)public class Outer{ 4)public static class Inner{ 5)} 6)} which is true to instantiated(事例) Inner class inside Outer? A. new Outer.Inner() B. new Inner() Answer: a,b 25. class BaseClass{ private float x=1.0f; private float getVar(){return x;} } c

38、lass SubClass extends BaseClass{ private float x=2.0f; //insert code } what are true to override getVar()? A.float getVar(){ B.public float getVar(){ C.public double getVar(){ D.protected float getVar(){ E.public float getVar(float f){ Answer: a,b,d 又是override的问题,参数列表和返回值以

39、及措施名(仿佛是费话)必须精准匹配,访问控制要更公有化,假如抛出异常,那么必须异常自身或其子集或什么都不抛. 26. public class SychTest{ private int x; private int y; public void setX(int i){ x=i;} public void setY(int i){y=i;} public Synchronized void setXY(int i){ setX(i); setY(i); } public Synchronized boolean check

40、){ return x!=y; } } Under which conditions will check() return true when called from a different class? A.check() can never return true. B.check() can return true when setXY is callled by multiple threads. C.check() can return true when multiple threads call setX and

41、 setY separately. D.check() can only return true if SychTest is changed allow x and y to be set separately. Answer: c 27. Given: 1. public class SyncTest ( 2. private int x; 3. private int y; 4. private synchronized void setX (int i) (x=1;) 5. private synchronized void

42、 setY (int i) (y=1;) 6. public void setXY(int 1)(set X(i); setY(i);) 7. public synchronized Boolean check() (return x !=y;) 8. ) Under which conditions will check () return true when called from a different class? A. Check() can never return true B. Check() can return true w

43、hen setXY is called by multiple threads C. Check() can return true when multiple threads call setX and setY separately. D. Check() can only return true if SyncTest is changed to allow x and y to be set separately. Answer:B 28. Given: 1. public class SyncTest { 2. private int

44、 x; 3. private int y; 4. public synchronized void setX (int i) (x=1;) 5. public synchronized void setY (int i) (y=1;) 6. public synchronized void setXY(int 1)(set X(i); setY(i);) 7. public synchronized Boolean check() (return x !=y;) 8. ) Under which conditions will check ()

45、 return true when called from a different class? A. Check() can never return true. B. Check() can return true when setXY is called by multiple threads. C. Check() can return true when multiple threads call setX and setY separately. D. Check() can only return true if SyncTest is changed to allow

46、x and y to be set separately. Answer: A 哪一个不加锁,就从哪一个入手,但这道题全都加锁了,因此先A。 29. 1)public class X implements Runnable{ 2)private int x; 3)private int y; 4)public static void main(String[] args){ 5) X that =new X(); 6) (new Thread(that)).start(); 7) (new Thread(that)).start(); }

47、 9) public synchronized void run(){ 10) for(;;){ 11) x++; 12) y++; 13) System.out.println("x="+x+",y="+y); 14) } 15) } 16) } what is the result? A.An error at line 11 causes compilation to fail. B.Errors at lines 6 and 7cause compilation to fail. C.The program p

48、rints pairs of values for x and y that might not always be the same on the same line (for example, “x=2, y=1”) D.The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” follow

49、ed by “x=1, y=1”) E.The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by “x=2, y=2”) Answer: E 这道题有问题,当两个线程同名时,输出x=1,y=1……,但只一次,而当两个线程不一样名时,输出就是两次。理论上加锁时,线程1

50、会执行直到结束,然后线程2才会开始执行。 30. Click the exhibit button: 1. public class X implements Runnable( 2. private int x; 3. private int y; 4. 5. public static void main(String[]args) 6. X that = new X(); 7. (new Thread(that)).start(); 8. (new Thread(that)).start(); 9.

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服