摩卡笔试题.pdf
《摩卡笔试题.pdf》由会员分享,可在线阅读,更多相关《摩卡笔试题.pdf(71页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、1:1.Give this class outline:2.class Example3.private int x;4./rest of class body.5.)6.Assuming that x invoked by the code java Example,which statement can made x be directly accessible in main()method of Example.java?J A.Change private int x to public int xJ B.change private int x to static int xnJ
2、C.Change private int x to protected int xJ D.change private int x to final int x2:Which of the following answer is correct to express the value 8 in octal number?e A.010C B.OxIO口 C.08C D.0 x83:在下述选项时,没有构成死循环的程序是C A.int i=100 while(1)i=i%100+1;if(i100)break;C B.for区 C.int k=1000;do +k;while(k=10000);
3、D.int s=36;while(s);-s;4:1.Give the following java class:2.public class Example3.static int x=new int15;4.public static void main(String args)5.System.out.println(x5);6.)7.)8.Which statement is corrected?A.When compile,some error will occur.B.When run,some error will occur.C.Output is zer|.0.Output
4、is null.1.What will happen when you attempt to compile and run the following code?2.3.(Assume that the code is compiled and run with assertions enabled.)4.5.public class AssertTest6.7.public void methodA(int i)8.9.assert i=0:methodB();10.11.System.out.println(i);12.13.14.15.public void methodB()16.1
5、7.System.out.println(The value must not be negative);18.19.20.21.public static void main(String args)22.23.AssertTest test=new AssertTest();24.25.test.methodA(-10);26.27.28.29.A.it will print-10B.it will result in Assertion Error showing the messageJtthe value must not be negative.C.the code will no
6、t compile.D.None of these.1.1.public class X 2.2.public object m()3.3.object o=new float(3.14F);4.4.object oa=new object 1;5.5.oa0=o;6.6.o=null;7.7.oa0=null;8.8.return o;9.9.10.10.11.When is the float object created in line 3,eligible for garbage collection?cA.Just after line 5B.Just after line 60 C
7、.Just after line 7J D.Just after line 8(that is,as the method returns)7:A class design requires that a member variable should be accessible only by same package,which modifer word should be used?J A.protected,B.publicJ C.no modifer-D.private8:Which statements about Java code security are not true?nJ
8、 A.The bytecode verifier loads all classes needed for the execution of a program.nJ B.Executing code is performed by the runtime interpreter.nJ C.At runtime the bytecodes are loaded,checked and run in an interpreter.n D.The class loader adds security by separating the namespaces for the classes of t
9、he localfile system from those imported from network sources.9:设有变量说明语句int a=1,b=0;则执行以下程序段的输出结果为()。switch(a)(case 1:switch(b)(case 0:printf(*0*H);break;case 1 :printf(*r*);break;)case2:printf(*2*);break;)printf(un);A.*0*B*Q*2*cQ*0*2*D.有语法错误10:Which method you define as the starting point of new thr
10、ead in a class from which new thethread can be excution?J A.public void start()B.public void run()pJ C.public void runnable()nJ D.public static void main(String args)11:1.下述程序代码中有语法错误的行是()。2.inti,ia10,ib10;/*第一行*/3.for(i=0;i=9;i+)/*第 2 行*/4.iai=0;/*第 3 行*/5.ib=ia;/*第 4 行*/A.第1行B.第2行C.第3行D.第4行12:鉴于Ja
11、va的特点,它最适合的计算环境是口 A.并行计算环境C B.分布式计算环境C c.高强度计算环境C D.开放式计算环境13:假 定a和b为int型变量,则执行下述语句组后,b的值为a=1;b=10;do(b-=a;a+;while(b-=0:methodBO;System.out.println(i);public void methodB0System.out.println(nThe value must not be negative);public static void main(String args)AssertTest test=new AssertTestOitest.met
12、hodA(-lO);)What will happen when you attempt to compile and run the following code?(Assume that the code is compiled and run with assertions enabled.)public class AssertTest(public void methodA(int i)assert i=0 methodBO;System.out.println(i);p u b l i c v o i d m e t h o d B()S y s t e m.o u t.p r i
13、 n t l n(T h e v a l u e m u s t n o t b e n e g a t i v e);p u b l i c s t a t i c v o i d m a i n(S t r i n g a r g s )As s e r t T e s t t e s t =n e w As s e r t T e s t O;t e s t.m e t h o d A(-l 0);j A.i t w i l l p r i n t -10J B.i t w i l l r e s u l t i n As s e r t i o n Er r o r s h o w i
14、 n g t h e m e s s a g e-ut h e v a l u e m u s t n o t b en e g a t i v e”.J C.t h e c o d e w i l l n o t c o m p i l e.i D.No n e o f t h e s e.4:In t h e f o l l o w i n g c o d e,w h i c h i s t h e e a r l i e s t s t a t e m e n t,w h e r e t h e o b j e c t o r i g i n a l l y h e l d in e,m
15、 a y b e g a r b a g e c o l l e c t e d-1.p u b l i c c l a s s T e s t 2.p u b l i c s t a t i c v o i d m a i n (S t r i n g a r g s )3.Em p l o y e e e =n e w Em p l o y e e(,Bo bM,48);4.e.c a l c u l a t e P a y O;5.System.out.println(e.printDetailsO)j6.e=null;7.e=new EmployeeCDenise,36);8.e.ca
16、lculatePayO;9.System.out.println(e.printDetailsO)J10.11.)Only One-In the following code,which is the earliest statement,where the object originally held ine,may be garbage collected-1.public class Test 2.public static void main(String args)3.Employee e=new Employee(nBobH,48);4.e.calculatePayO,5.Syst
17、em.out.println(e.printDetailsO);6.e=null;7.e=new Employee(HDenisen,36);8.e.calculatePayO?9.System.out.println(e.printDetailsO);10.11.)Only One-J A.Line 10C B.Line 11C C.Line 7C D.Line 85:The following code is entire contents of a file called Example.java,causes precisely oneerror during compilationc
18、lass SubClass extends BaseClassclass BaseClass()String str;public BaseClass()System.out.println(aok,)jpublic BaseClass(String s)str=s;public class Example(public void method0SubClass s=new SubClass(hello);BaseClass b=new BaseClass(world);Which line would be cause the error?The following code is enti
19、re contents of a file called Example.java,causes precisely oneerror during compilation:class SubClass extends BaseClass)class BaseClass()String str;p u b l i c Ba s e Cl a s s()S y s t e m.o u t.p r i n t l n(uo k,);)p u b l i c Ba s e Cl a s s(S t r i n g s)s t r=s;p u b l i c c l a s s Ex a m p l
20、e!p u b l i c v o i d m e t h o d O(S u b Cl a s s s=n e w S u b Cl a s s Ch e l l o);Ba s e Cl a s s b=n e w Ba s e Cl a s s(w o r l d);W h i c h l i n e w o u l d b e c a u s e t h e e r r o r?C A.9J*B.10口 C.UC D.126-W h a t i s w r i t t e n t o t h e s t a n d a r d o u t p u t g i v e n t h e f
21、 o l l o w i n gs t a t e m e n t-S y s t e m.o u t.p r i n t l n(4|7);S e l e c t t h e r i g h t a n s w e r*C A.4C B.5C C.6 D,77:S e l e c t v a l i d i d e n t i f i e r o f Ja v a-S e l e c t v a l i d i d e n t i f i e r o f Ja v a-A.%p a s s w dB.3d _ g a m eJ C.$c h a r g eo D.t h i s8:关于垃圾收
22、集的哪些叙述是对的。C A.程序开发者必须自己创建一个线程进行内存释放的工作。C B.垃圾收集将检查并释放不再使用的内存。c.垃圾收集允许程序开发者明确指定并立即释放该内存。C D.垃圾收集能够在期望的时间释放被j a v a对象使用的内存。9:A c l a s s d e s i g n r e q u i r e s t h a t a p a r t i c u l a r m e m b e r v a r i a b l e m u s t b e a c c e s s i b l e f o r d i r e c ta c c e s s b y a n y s u b c
23、l a s s e s o f t h i s c l a s s,b u t o t h e r w i s e n o t b y c l a s s e s w h i c h a r e n o tm e m b e r s o f t h e s a m e p a c k a g e.W h a t s h o u l d b e d o n e t o a c h i e v e t h i s?J A.T h e v a r i a b l e s h o u l d b e m a r k e d p u b l i cJ B.T h e v a r i a b l e s
24、h o u l d b e m a r k e d p r i v a t eJ C.T h e v a r i a b l e s h o u l d b e m a r k e d p r o t e c t e dJ D.T h e v a r i a b l e s h o u l d h a v e n o s p e c i a l a c c e s s m o d i f i e r10:W h a t w i l l h a p p e n w h e n y o u a t t e m p t t o c o m p i l e a n d r u n t h e f o
25、l l o w i n g c o d e?c l a s s Ba s ei n t i =99;p u b l i c v o i d a m e t h o d OSystem.out.println(,Base.amethodOn)JBaseOamethodO;public class Derived extends Baseint i=-1;public static void main(String argv)Base b=new Derived。;System.out.println(b.i);b.amethodO;public void amethodOSystem.out.p
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 笔试
限制150内