Java测试题(150分钟)一、选择题(25*3分)(不定项选择)1.阅读以下代码,运行结果为()public class ExamT est {public static void main(String[] args) {List<String> strList = new ArrayList<String>();strList.add("a") ;strList.add("b") ;strList.add("c") ;strList.add("d") ;int size = strList.size() ;for(int i = 0 ; i<size ; i++){strList.remove(i);}Sy stem.out.println(strList.size());}}A. 4B.2C. 0D. 运行出错2.在JSP中有下面代码,执行结果正确的是()<%int x ;for(int i = 0 ; i<5 ; i++){x = ++i ;%><%=x++%><%}%>A. 1 2 3 4 5B. 1 2 3 4C. 1 3 5D. 2 4 63.小明在进行×××项目时,需要使用到Collection集合。
他需要保存一系列的数据,但是这个数据集合变动比较频繁,总是频繁的进行插入和删除操作,那么他应该选择下列哪一数据类型。
A.LinkedListB.ArrayListC.CollectionD.HashMap4.JSP页面中如下代码的运行结果是()<%String userName = "IFLYTEK" ;session.setAttribute("userName" , userName);%><!--....此处省略了部分代码....--><%String userName = session.getAttribute("userName");out.println(userName);%>A.乱码B.运行错误C.IFL YTEKD.无显示5.如果要让如下代码运行结果为”Sub Method”,下面选项中可以填入下划线处的是()public class ExamT est {public static void main(String[] args) {___________________________}}class Base{public void method(){Sy stem.out.println("Base Method");}}class Sub extends Base {public void method(){Sy stem.out.println("Sub method");}public void methodB(){Sy stem.out.println("Sub methodB");}}A.Base base = new Sub();base.method() ;B.Base base = new Sub();base.methodB();C.Sub sub = new Base();sub.method();D.Base sub = new Base();sub.method();6.在java中,以下程序的编译运行结果是()public class ExamT est {public static void main(String[] args) {new Base().print();}}class Base{public Base(int i){}public void print(){Sy stem.out.println("hello iflytek!");}}A.输出:hello iflytek!B.运行时错误C.编译错误D.运行正常但没有任何输出7.阅读以下java代码,在横线处填入一行代码,不能填在横线处的是()class Book{String bookName ;int pageNum ;public Book(){}public Book(int pageNum){______________}}A.super.toString();B.Sy stem.out.println(super);C.super;D.this();8.以下程序运行的结果是()public class ExamT est {public static void main(String[] args) {Base b = new Son();Sy stem.out.println();b.hello();}}class Base{public String name ="Base " ;public void hello(){Sy stem.out.println("Base hello ");}}class Son extends Base{public String name = "Son" ;public void hello(){Sy stem.out.println("Son hello");}}A.SonSon helloB.BaseBase helloC.BaseSon helloD.SonBase hello9.以下程序的输出结果为()public class ExamT est {public static void main(String[] args) {Cal c = new Cal();Sy stem.out.println(c.methodA());}}class Cal{int i = 5 ;static int j = 10 ;public static int methodA(){return methodB() * 2 ;}public int methodB(){return i + j ;}}A.15B. 30C.20D.编译出错10.运行以下代码将输出()public class ExamT est {public static void main(String[] args) {new B("Jim");}}class A{{Sy stem.out.println("A");}static{Sy stem.out.println("A static ");}public A(){Sy stem.out.println("A constructor");}}class B extends A{static{Sy stem.out.println("B static");}public B(){Sy stem.out.println("B constructor");}public B(String name){Sy stem.out.println("B constructor 2 ");}}A. B constructor 2B. B constructor 2A constructorC. A staticB staticA constructorAB constructor 2D. A staticB staticAA constructorB constructor 211.阅读以下程序,运行结果为()public class ExamT est {public static void main(String[] args) {new Derived();}}class Base{private int i = 2 ;public Base(){this.display();}public void display(){Sy stem.out.println(i);}}class Derived extends Base{private int i = 22 ;public Derived(){i = 222 ;}public void display(){Sy stem.out.println(i);}}A. 2B. 22C. 222D. 012.阅读下列代码:public class ExamT est {public static void main(String[] args) {Play er c1 = new CardPlay er();c1.i=100;try {FileOutputStream fos = new FileOutputStream("play.txt");ObjectOutputStream os = new ObjectOutputStream(fos);os.writeObject(c1);os.close();FileInputStream fis = new FileInputStream("play.txt");ObjectInputStream is = new ObjectInputStream(fis);CardPlay er c2 = (CardPlayer) is.readObject();is.close();Sy stem.out.println(c2.i);} catch (Exception x) {}}}class Play er {int i = 9 ;Play er() {Sy stem.out.print("p");}}class CardPlay er extends Play er implements Serializable {CardPlay er() {Sy stem.out.print("c");}}运行以上代码,控制台打印结果为:A. pcB. pccC. pcp9D. pcp100E. pcpc9F. pcpc100G. Compilation fails H. An exception is thrown at runtime13.阅读下面的代码public class ExamT est {public static void main(String[] args) {Cathedral c = new Cathedral();____________________s.go();}}class Cathedral {class Sanctum {void go() {Sy stem.out.println("spooky");}}}以下哪个选项的代码插入到横线处,可以输出A. Sanctum s = c.new Sanctum();B. c.Sanctum s = c.new Sanctum();C. c.Sanctum s = Cathedral.new Sanctum();D. Cathedral.Sanctum s = c.new Sanctum();E. Cathedral.Sanctum s = Cathedral.new Sanctum();14.执行以下代码,控制台将输出:()public class ExamT est {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) ;Sy stem.out.println(output);}}A.13423B. 124234C. 134234D. 134215.运行以下程序,控制台将打印:()public class ExamTest {public static void main(String[] args) {System.out.println(new Wolf("灰太狼", 32.3));}}class Animal{private String desc ;public Animal(){this.desc = getDesc();}public String getDesc(){return "Animal" ;}public String toString(){return desc ;}}class Wolf extends Animal{private String name ;private double weight ;public Wolf(String name , double weight ){ = name ;this.weight = weight ;}public String getDesc(){return "Wolf[name=" + name + ", weight="+weight + "]" ;}}A.Wolf[name=null, weight=0.0]B.AnimalC.Wolf[name=灰太狼, weight=32.3]D.程序有错误16.运行下面的程序,控制台打印结果为:( )public class ExamTest {public static void main(String[] args) {String s1 = "Hello World" ;String s2 = "Hello " + "World" ;String temp1 = "Hello " ;String temp2 = "World" ;String s5 = temp1 + temp2 ;boolean flag1 = s1 ==s2 ;boolean flag2 = s1==s5 ;System.out.println("flag1:"+flag1);System.out.println("flag2:"+flag2);}}A.true trueB.true falseC.false falseD.false true17.阅读下列代码,选项正确的是:()import java.util.*;class Business { }class Hotel extends Business { }class Inn extends Hotel { }public class Travel {ArrayList<Hotel> go() {// insert code here}}应当插入那个代码:A. return new ArrayList<Inn>();B. return new ArrayList<Hotel>();C. return new ArrayList<Object>();D. return new ArrayList<Business>();18.阅读下列代码,运行的结果为:()class Person{public Person(String name , int age){……..}……}class T est{public static void main(String[] args){Set<Person> persons = new TreeSet<Person>();persons.add(new Person(“lili”,20));persons.add(new Person(“jim”,25));Sy stem.out.println(persons.size());}}A.0B. 1C. 2D. 运行报错19.Java语言中,下列时处理流操作的所有类的基础的是()A、InputStreamB、OutputStreamC、BufferedOutputStreamD、IOStream20.下列哪一步操作会使得线程进入运行状态()A.Thread t = new Thread();B.Thread t = new Thread();t.start();C.Thread t = new Thread();t.sleep();D.以上答案都不对21.JAVA语言中的套接字(Socket)是一种基于网络进程通信的接口,是网络通信协议的一种应用。