中信Java笔试题.doc
如有侵权,请联系网站删除,仅供学习与交流中信Java笔试题【精品文档】第 29 页Java笔试题不定项选择题,50题,每题2分,共100分Question 1) Answer:AB_给出下列代码: 1. switch ( I ) 2. default: 3. System.out.printIn(“Hello”); 4. ) i类型是什么? A. short B. char C. long, D. stringQuestion 2) Answer:_AD_依次读入数据元素序列a,b,c,d,e,f,g进栈,每进一个元素,机器可要求下一个元素进栈或弹栈,如此进行,则栈空时弹出的元素构成的序列是以下哪些序列?Ad ,e,c,f,b,g,a B. f,e,g,d,a,c,bC. e,f,d,g,b,c,a D. c,d,b,e,f,a,gQuestion 3) Answer:_A(B)CD_以下关于重写和重载的描述那些是正确的?A. 重写Overriding是父类与子类之间多态性的一种表现;B. 重载Overloading是一个类中多态性的一种表现;C. Overloaded的方法是可以改变返回值的类型;D. 构造器Constructor可以被重载Overloading。Question 4) Answer:_A_定义类A和类B如下: class A +z?Uj kq# int a=1; f,Ens?d double d=2.0; r6EasP? void show() q dd W1+ System.out.println("Class A: a="+a +"td="+d); "tGg E juj _(Yh( x$siq= class B extends A _%HD%q float a=3.0f; r%B"bukX2 String d="Java program." >XM-B void show() h9 daH5R super.show( ); > .-QI: System.out.println("Class B: a="+a +"td="+d); mdb8%iL rE+kkwsj JplCgmM0 若在应用程序的main方法中定义类B的对象b: x_LlO A b=new B(); 3>+!Y/A b.show(); pa_dd 则输出的结果如何?A. =4_n B Class A: a=1 d=2.0 .WG|PM9f Class B: a=3.0d=Java program. d=vRztB Class A: a=1 d=2.0 .WG|PM9f Class B: a=3.0C. Class A: a=1 d=2.0 .WG|PM9f d=Java program.D. Class B: a=3.0d=Java program. d=vRztQuestion 5) Answer:_AC(B)_关于wait()方法和sleep()方法的区别,以下说法错误的是:A. wait ()方法是使线程停止一段时间的方法;B. sleep ()是线程交互时,如果线程对一个同步对象x 发出一个sleep ()调用,该线程会暂停执行;C. 在wait时间间隔期满后,线程立即恢复执行;D. 在sleep 时间间隔期满后,线程不一定立即恢复执行Question 6) Answer:_D_如果只想得到1000个元素组成的序列中第5个最小元素之前的部分排序的序列,用( )方法最快。A起泡排序 B快速排列 CShell排序 D堆排序 E简单选择排序Question 7) Answer:_C_以下代码执行结果是? 1)class MyThread extends Thread 2) 3) public static void main(String args) 4) MyThread t=new MyThread(); 5) t.run(); 6) 7) 8)public void run()9)for(int i=1;i<3;+i) 10)System.out.print(i+”.”); 11) 12) 13) A. 因为第4行有问题,所以无法编译 B. 因为第5行,所有以无法编译:C. 打印出:1.2. D. 打印出:1.2.3.Question 8) Answer:_C_实例变量不需要初始化,局部变量必须初始化。对于以下代码,哪种说法是对的?class Something boolean i; public void doSomething() System.out.println("i = " + i);A. 编译时出错;B. 编译通过,运行时出错;C. 没有错误,输出的是"i = false";D. 没有错误,输出的是"i = null"。Question 9) Answer:_C_堆排序所需的辅助空间少于快速排序,并且不会出现快速排序可能出现的最坏情况。这两种排序都是不稳定的。下列排序算法中,占用辅助空间最多的是:( ) A. 归并排序 B. 快速排序 C. 希尔排序 D. 堆排序Question 10) Answer:_A_对于以下代码,哪种说法是对的?public class Something public static void main(String args) Other o = new Other();/-(1)- new Something().addOne(o); public void addOne(final Other o) /-(2)- o.i+;class Other public int i;A. 代码正确;B. 编译时在(1)处出错;C. 编译时在(2)处出错;D. 编译通过,运行时出错。Question 11) Answer:_AD_不能用来修饰interface的有( )Aprivate Bpublic Cprotected Dstatic Question 12) Answer:_C_执行如下程序代码后,C的值是( )a=0;c=0;do-c;a=a-1;while(a>0);A0 B1 C-1 D死循环Question 13) Answer:_C_如果testMethod运行正常,将显示? public void test() try testMethod();catch(ArrayIndexOutOfBoundsException e)System.out.println(“test1”); catch(Exception e) System.out.println(“test2”); finally System.out.println(“test3”);A. test1 B. test2 C. test3 D. 没有显示Question 14) Answer:_B_给出下列代码:在第六行中放入那个方法会引起编译错误:1. class super 2. public float getNum() return 3.0f; 3. 4. 5. public class Sub extends Super 6. 7. A. public float getNum() return 4.0f; B. public void getNum () C. public void getNum (double d) D.public double getNum (float d) retrun 4.0f; Question 15) Answer:_B_下面说法错误的是( )若排序算法所需的辅助空间并不依赖于问题的规模n,即辅助空间是O(1),则称之为就地排序(In-PlaceSou)。 (1)算法原地工作的含义是指不需要任何额外的辅助空间 (2)在相同的规模n下,复杂度O(n)的算法在时间上总是优于复杂度O(2n)的算法 (3)所谓时间复杂度是指最坏情况下,估算算法执行时间的一个上界 (4)同一个算法,实现语言的级别越高,执行效率就越低 A(1) B.(1),(2) C.(1),(4) D.(3)Question 16) Answer:_B_Java 中byte类型的范围是?A. 0 65, 535 B. (128)127C. (32,768) 32,767D. (256) 255Question 17) Answer:_D_(编译不通过,原因是没有实现 runnable的run()方法)以下程序执行后的结果是什么?1. public class Foo implements Runnable ( 2. public void run (Thread t) 3. System.out.printIn(“Running.”);4. 5. public static void main (String args) 6. new thread (new Foo().start(); 7. ) 8. ) A. 程序运行,什么都没有打印 B. 程序运行,打印“Running”C. 编译通过,执行时发生异常 D. 编译不通过,因为缺少catch模块Question 18) Answer:_ABCD_ _下面有关变量及其作用域的陈述哪些是正确的?A. 在方法里面定义的局部变量在方法完成的时候被销毁 B. 局部变量也叫自动变量。(方法/栈/自动)C. 在方法外面定义的变量(即实例变量)在对象被构造时创建。D. 在方法中定义的方法的参变量只要该对象被需要就一直存在。(方法被调用的时候才存在)Question 19) Answer:_C_以下程序输出的结果是 public class Foo public static void main (String args) StringBuffer a = new StringBuffer(“A”); StringBuffer b = new StringBuffer(“B”); operate(a,b); System.out.println(a + “,”+b); static void operate (StringBuffer x, StringBuffer y) x.append(y); y = x;A. 程序打印 “A,B” B. 程序打印 “A,A”C. 程序打印 “AB,B” D. 代码不能编译通过,因为“+”不能在StringBuffer中重载Question 20) Answer:_D_给出下面的代码,哪些行将导致错误。 class Parent private String name; /-1) public Parent() public class Child extends Parent /- 2) private String department; /-3) public Child() public String getValue() return name; /-4)public static void main(String arg) /-5) Parent p = new Parent(); A. line 1) B. line 2) C. line 3)D. line 4)Question 21) Answer:_D_以下程序运行结果中下面的哪些正确: class Parent String one,two; public Parent(String a, String b) one = a; two = b; public void print() System.out.println(one);public class Child extends Parent public Child(String a, String b) super(a,b); public void print() System.out.println(one + “ to “ + two); public static void main(String arg) Parent p = new Parent(“south”, “north”); Parent t = new Child(“east”, “west”); p.print(); t.print(); A. 编译时发生错误 B. south east C. south to north east to westD. south east to westQuestion 22) Answer:_D_以下程序执行后的结果是: int i= 1, j= 10 ; do ( if (i+> -j) continue; while (i<5); A. i = 6 and j= 5 B. i = 5 and j= 5 C.i = 6 and j= 4 D. i = 5 and j= 6Question 23) Answer:_D_以下关于使用JUnit的说法,正确的有:A. 对每个测试类,都要定义一个测试用例。B. Error错误是一个期望的被assert方法检查到的结果。C. Faile失败则是意外的问题引起的。D. 当JUnit执行测试时,它在执行每个testXXXXX()方法前都调用setUp(),初始化所有测试的Fixture;而在执行每个testXXXXX()方法后都调用tearDown()方法,释放你在setUp()中分配的永久性资源。Question 24) Answer:_C_下面代码的显示结果是_TrySystem.out.println(“1”);Throw exception();Catch(exception e)System.out.println(“2”);FiniallySystem.out.println(“3”);A. 13;B. 12;C. 123;D. 23。Question 25) Answer:_BC_关于session的论述正确的有:A.一个session可以对应数个用户B.一个session只能对应一个用户C.可以手动关闭一个sessionD.session如果不手动关闭,会一直存在Server中Question 26) Answer:_B_下列代码哪一行会出错? public void modify() 1) int I,j,k;2) I=100;3) while (I>0) 4) j=I*2;5) System.out.println(“ The value of j is ”+j);6) k=k+1;7) I-;A.line 4 B.line 6C.line 7 D.line 8Question 27) Answer:_C_以下代码输出的结果是:package com.systop.questions;public class PingPong public static synchronized void main(String a) throws Exception Thread t = new Thread() public void run() pong(); t.run(); System.out.print( "Ping" ); static synchronized void pong() System.out.print( "Pong" );A. 编译时出错;B. 编译通过,运行时出错;C. 输出:PongPing;D. 输出:PingPong。Question 28) Answer:_D_以下代码输出的结果是:package com.systop.questions;public class PingPong public static synchronized void main(String a) throws Exception Thread t = new Thread() public void run() pong(); t.start(); System.out.print( "Ping" ); static synchronized void pong() System.out.print( "Pong" );A. 编译时出错;B. 编译通过,运行时出错;C. 输出:PongPing;D. 输出:PingPong。Question 29) Answer:_C_以下代码的输出结果是:public static String allBytes() for(byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b+) if(b = 0x90) return "HaHa" return ""A. 编译时出错;B. 编译通过,运行时出错;C. 没有输出结果;D. 输出:HaHa。Question 30) Answer:_AC_以下代码合法的有:A. Object x = "Buy "String i = "Effective Java!" x = x + i;B. Object x = "Buy "String i = "Effective Java!" x += i; C. short x = 0; int i = 123456; x += (short)i;x = (short)(x + (short)i);D. short x = 0; int i = 123456; x = x + i;Question 31) Answer:_A_以下程序的正确输出是:public class Foo public static void main (String args) StringBuffer a = new StringBuffer (“A”); StringBuffer b = new StringBuffer (“B”); operate (a,b); system.out.println(a + “,” +b);static void operate (StringBuffer x, StringBuffer y) x.append (y); y = x;A. AB,B;B. A,B;C. B,B;D. A,BB。Question 32) Answer:_B_what is the value of output at line 24?public class Test public static String output="" public static void foo(int i) try if(i=1) throw new Exception(); output +="1" catch(Exception e) output+="2" return; finally output+="3" output+="4" public static void main(String args) foo(0); foo(1); /-24) A. 1342;B. 13423;C. 134234;D. 134232。Question 33) Answer:_ABD_下列哪些情况可以终止当前线程的运行?A. 抛出一个例外时;B. 当该线程调用sleep()方法时;C. 当创建一个新线程时;D. 当一个优先级高的线程进入就绪状态时。Question 34) Answer:_B_下列程序的运行结果是:class A class Dog private String name; private int age; public int step; Dog(String s,int a)name=s;age=a;step=0;public void run(Dog fast)fast.step+;public static void main (String args)A a=new A(); Dog d=a.new Dog("Tom",3);d.step=25; d.run(d); System.out.println(d.step); A. 25;B. 26;C. 3;D. 4。Question 35) Answer:_ABC_以下描述ArrayList,Vector, LinkedList的存储性能和特性正确的是A. ArrayList和Vector都是使用数组方式存储数据;B. Vector允许直接按序号索引元素;C. LinkedList使用双向链表实现存储;D. Vector由于使用了synchronized方法(线程安全),通常性能上较ArrayList好。Question 36) Answer:_C_下面的哪些叙述为真。A. equals()方法判定引用值是否指向同一对象。B. = 操作符判定两个分立的对象的内容和类型是否一致。 C. equals()方法只有在两个对象的内容一致时返回true。 D. 原始类型可以使用equals()方法Question 37) Answer:_A_What happens when you try to compile and run the following application? Choose all correct options. 1. public class Z 2. public static void main(String args) 3. new Z(); 4. 5. 6. Z() 7. Z alias1 = this; 8. Z alias2 = this; 9. synchronized(alias1) 10. try 11. alias2.wait(); 12. System.out.println(“DONE WA99vING”); 13. 14. catch (InterruptedException e) 15. System.out.println(“INTERR UPTED”); 16. 17. catch (Exception e) 18. System.out.println(“OTHER EXCEPTION”); 19. 20. finally 21. System.out.println (“FINALLY”);22. 23. 24. System.out.println(“ALL DONE”); 25. 26. A. The application compiles but doesn't print anything. B. The application compiles and print “DONE WA99vING” C. The application compiles and print “FINALLY” D. The application compiles and print “ALL DONE” E. The application compiles and print “INTERRUPTED”Question 38) Answer:_B_下面的哪些关键字通常用来对对象的加锁,该标记使得对对象的访问是排他的 ?A. transientB. synchronizedC. serializeD. staticQuestion 39) Answer:_D_已知以下代码片断 byte a = 127; byte b = 126; byte c = a + b; 下面的的哪些叙述是对的: A. c的值为243B. c的值为244 C. 第一行编译错误 D. 第三行编译错误Question 40) Answer:_C_String str = null; /-1 if (str != null) && (str.length() > 10)/-2 System.out.println(“more than 10”); else if (str != null) & (str.length() < 5)/-5 System.out.println(“less than 5”); else System.out.println(“end”); /- 8 哪些行将导致错误A. 行1B. 行2C. 行5D. 行8Question 41) Answer:_C_class Aclassvoid go()System.out.println(“Aclass”); public class Bclass extends Aclassvoid goSystem.out.println(“Bclass”);public static void main(String args)Aclass a=new Aclass();Aclass a1=new Bclass();a.go();a1.go(); 以上程序运行结果是: A. Aclass Aclass B. Bclass BclassC. Aclass Bclass D. Bclass Aclass Question 42) Answer:_A_boolean a=false; boolean b=true; boolean c=(a&&b)&&(!b); int result=c=false?1:2; 这段程序执行完后,c与result的值是: A. c=false;result=1; B. c=true;result=2;C. c=true;result=1; D. c=false;result=2;Question 43) Answer:_BC_下列关于修饰符混用的说法,错误的是:A. abstract不能与final并列修饰同一个类 B. abstract类中不可以有private的成员 C. abstract方法必须在abstract类中 D. static方法中能处理非static的属性 Question 44) Answer:_C_class Person String name, department; int age; public Person(String n) name = n; public Person(String n, int a) name = n; age = a; public Person(String n, String d, int a) / 补充和具有两个参数的构造函数一样功能的代码 department = d; 下面的哪些表达式可以加到构造方法中的”/补充”处:A. Person(n,a); B. this(Person(n,a); C. this(n,a); D. this(name,age);Question 45) Answer: _D_Which of the statements below is true?1. class Test 2. void test(int i) 3. System.out.println(“I am an int.”); 4. 5. void test(String s) 6. System.out.println(“I am a string.”); 7. 8. 9. public static void main(String args) 10. Test t=new Test(); 11. char ch=y; 12. t.test(ch); 13. 14. A. Line 5 will not compile, because void methods cannot be overridden. B. Line 12 will not compile, because there is no version of test() that rakes a char argument. C. The code will compile but will throw an exception at line 12. D. The code will compile and produce the following output: I am an int. E. The code will compile and produce the following output: I am a String. Question 46) Answer:_ACD_有如下代码,哪些返回trueString s= "hello"String t =