一、選擇題
1、下面哪些是java語言中的關(guān)鍵字? A sizeof B abstract C NULL D Native 答:B
2、下面語句哪個是正確的? A char='abc'; B long l=oxfff; C float f=0.23; D double=0.7E-3; 答:D
3、以下程序測試String 類的各種構(gòu)造方法,試選出其運行效果。
public class abc {
public static void main(String args[]){
String s1=new String();
String s2=new String("String 2");
char chars[]={'a',' ','s','t','r','i','n','g'};
String s3=new String(chars);
String s4=new String(chars,2,6);
byte bytes[]={0,1,2,3,4,5,6,7,8,9};
StringBuffer sb = new StringBuffer(s3);
String s5=new String(sb);
System.out.println("The String No.1 is "+s1);
System.out.println("The String No.2 is "+s2);
System.out.println("The String No.3 is "+s3);
System.out.println("The String No.4 is "+s4);
System.out.println("The String No.5 is "+s5);
}
}
A The String No.1 is
The String No.2 is String 2
The String No.3 is a string
The String No.4 is string
The String No.5 is a string
B The String No.1 is The String No.2 is String 2 The String No.3 is a string
The String No.4 is tring The String No.5 is a string
C The String No.1 is The String No.2 is String 2 The String No.3 is a string
The String No.4 is strin The String No.5 is a string
D 以上都不對
答:A
4、下面語句段的輸出結(jié)果是什么?
inti = 9; switch (i) {
default: System.out.println("default");
case 0: System.out.println("zero"); break;
case 1: System.out.println("one");
case 2: System.out.println("two"); }
A default
B default, zero
C error default clause not defined
D no output displayed
答:B
二、不定項選擇題(在每小題的五個備選答案中選出正確答案,并將正確答案的序號填入題干后面的括號內(nèi),錯選多選,漏選均不得分。)
1、給出如下代碼:
class Test{ private int m; public static void fun() { // some code... } } 如何使成員變量m 被函數(shù)fun()直接訪問?
A、將private int m 改為protected int m B、將private int m 改為 public int m
C、將private int m 改為 static int m D、將private int m 改為int m
答: C
2、下面哪幾個函數(shù)是public void example(){...}的重載函數(shù)?
A、 public void example( int m){...} B、public int example(){...}
C、public void example2(){...} D、 public int example ( int m, float f){...}
答: A,D