Java试题一、选择题(10×3分共30分)1、以下程序的输出结果是多少?public class Inc {/***@param args*/public static void main(String[] args) {Inc inc = new Inc();int i = 5;inc.fermin(i);i = i++;System.out.println(i);}void fermin(int i){i++;}}A.编译错误 B. 输出为6 C. 输出为5 D. 输出为72请问运行下面的程序会打印出的是什么?List list=new ArrayList();list.add("a");list.add("b");list.add("a");Set set=new HashSet();set.add("a");set.add("b");set.add("a");System.out.println(list.size());System.out.println(set.size());A.3 2 B. 3 3C. 2 3D. 2 23请输出以下结果/***@param args*/public static void main(String[] args) {String str = new String("World");char ch[] = {'H','e','l','l','o'};change(str,ch);System.out.print(str + " and ");System.out.println(ch);}public static void change(String str,char ch[]){str = "change";ch[0] = 'C';}A. World and Cello B. change and CelloC. World and HelloD. change and Hello4给定下面的程序public class Sytch{int x = 2000;public static void main(String args[]){System.out.println("Please pay $"+x);}}如果用命令行参数java Sytch Jones Diggle编译和运行上面的程序,结果怎样?A 编译错误B Please pay $ 2000C java Sytch Jones DiggleD Please pay $ java Sytch Jones Diggle5.以下整个过程中共产生过多少个对象?String A,B,C;A = "a";B = "b";A = A + B;StringBuffer D = new StringBuffer("abc");D = D.append("567");A.5 B. 6 C. 4 D. 36 Which of the following lines of code will compile without error?A.int i=0;if (i) {System.out.println(“Hi”);}B.boolean b=true;boolean b2=true;if(b==b2) {System.out.println(“So true”);}C.int i=1;int j=2;if(i==1|| j==2)System.out.println(“OK”);D.int i=1;int j=2;if (i==1 &| j==2)System.out.println(“OK”);7 下列哪些描述符合信息隐藏的设计原则?A 尽可能的使每个类或者成员不被外界访问B 将所有的方法,属性都定义为共有的。
C 应该使用与你正在编写的软件的对应功能相一致的,尽可能小的访问级别。
D 尽可能的使每个类或者成员被外界访问8 一下哪段代码一定不会被执行?try{CODE1...Return;CODE2...}catch(Exception e){CODE3...}finally{CODE4...}A CODE1B CODE3C CODE2D CODE49 给定下面的字符串定义:String s “aspire”;下面哪个表达式是合理的?A s+=5;B char c = s[1];C int len = s.length;D String t = s.toLowCase;10 下面代码中,第几行的sobj符合垃圾收集器的收集标准:Object sobj = new Object(); //line 1Object sobj = null; //line 2Object sobj = new Object(); //line 3sobj = new Object(); //line 4A line 1B line 2C line 3D line 4二、简答题(6×5分共30分)1 以下正则表达式表示什么含义?^oncebucket$^[a-z][0-9]$[^\"\']^[0-9]{1,}$2 以下jvm参数表示什么意思?-XX:NewSize-XX:MaxNewSize-XX:PermSize-XX:MaxPermSize-Xms-Xmx-Xloggc:file-XX:+PrintGCDetails-XX:+PrintGCTimeStamps请解释以下gc日志表示的含义:69.713: [GC 11536K->11044K(12016K), 0.0032621 secs 3x=x+1,x+=1及x++的效率哪个最高?为什么?4面向对象的特征有哪些?并详细描述一下:5接口和抽象类的区别二、编程题(5×8分共40分)1以下程序运行之后将会输出什么?class TestOne{int var;TestOne(double var){this.var = (int)var;}TestOne(int var){this("HELLO");}TestOne(String s){this();System.out.println(s);}TestOne(){System.out.println("GOOD-BYE");}public static void main(String args[]){TestOne t = new TestOne(1);}}2.以下两段代码运行有何不同?代码1:public class RandomTest{public static void main(String args[]){java.util.Random r = new java.util.Random(); for(int i=0;i<10;i++){System.out.println(r.nextInt());}}}代码2:public class RandomTest{public static void main(String args[]){java.util.Random r = new java.util.Random(10); for(int i=0;i<10;i++){System.out.println(r.nextInt());}}}3请说出以下代码的运行结果package sort;import java.util.List;public class InsertSort {public static int[] sort(int[] intArray) {int size = intArray.length;for (int i = 1; i < size; i++) {for (int j = i; intArray[j] < intArray[j - 1] && j > 0; j--) { int temp = intArray[j - 1];intArray[j - 1] = intArray[j];intArray[j] = temp;}}return intArray;}/***@param args*/public static void main(String[] args) {// TODO Auto-generated method stubint[] arr = { 2, 5, 7, 1, 6, 11, 3, 8 };InsertSort.sort(arr);for (int i : arr) {System.out.println(i);}}}4 写出下列程序的运行结果class MyThread extends Thread{public void run(){System.out.println("MyThread: run()");}public void start(){System.out.println("MyThread: start()");}}class MyRunnable implements Runnable{public void run(){System.out.println("MyRunnable: run()");}public void start(){System.out.println("MyRunnable: start()");}}public class MyTest {public static void main(String args[]){MyThread myThread = new MyThread();MyRunnable myRunnable = new MyRunnable();Thread thread = new Thread(myRunnable);myThread.start();thread.start();}}5写出下列程序的运行结果public class Test {public void test(int i) {System.out.println("I am an int.");}public void test(String s) {System.out.println("I am an String.");}public static void main(String[] args){ Test t=new Test();char ch='y';t.test(ch);}}。