《JAVA語(yǔ)言程序設(shè)計(jì)Ⅰ》在線平時(shí)作業(yè)1-00001
試卷總分:100 得分:100
一、單選題 (共 20 道試題,共 60 分)
1.若有循環(huán): int x=5,y=20; do{ y-=x; x++; }while(++x<--y);則循環(huán)體將被執(zhí)行( )。
A.0次
B.1次
C.2次
D.3次
2.下列代碼的執(zhí)行結(jié)果是 public class Test { public int aMethod() { static int i=0; i++; System.out.println(i); } public static void main(String args[]) { Test test = new Test();
A.編譯錯(cuò)誤
B.0
C.1
D.運(yùn)行成功,但不輸出
3.順序執(zhí)行下列程序語(yǔ)句后,則b的值是 String a="Hello"; String b=a.substring(0,2);
A.Hello
B.hello
C.Hel
D.null
4.給出下列代碼,如何使成員變量m 被方法fun()直接訪問(wèn)? class Test { private int m; public static void 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
5.已知如下代碼: boolean m = true; if ( m = false ) System.out.println("False"); else System.out.println("True"); 執(zhí)行結(jié)果是什么?
A.False
B.True
C.編譯時(shí)出錯(cuò)
D.運(yùn)行時(shí)出錯(cuò)
6.已知表達(dá)式int m[] = {0, 1, 2, 3, 4, 5, 6 }; 下面哪個(gè)表達(dá)式的值與數(shù)組下標(biāo)量總數(shù)相等?
A.length()
B.length
C.length()+1
D.length+1
7.下列語(yǔ)句序列執(zhí)行后,j 的值是( )。 Int j=3, i=2; while( --i!=i/j ) j=j+2;
A.2
B.4
C.5
D.6
8.設(shè)有下面的兩個(gè)類定義: class AA { void Show(){ System.out.println("我喜歡Java!"); } class BB extends AA { void Show(){ System.out.println("我喜歡C++!"); } 則順序執(zhí)行如下語(yǔ)句后輸出結(jié)果為:( ) AA a; BB b; a.Show(); b.Show();
A.我喜歡Java! 我喜歡C++!
B.我喜歡C++! 我喜歡Java!
C.我喜歡Java! 我喜歡Java!
D.我喜歡C++! 我喜歡C++!
9.在oneMethod()方法運(yùn)行正常的情況下,程序段將輸出什么? public void test() { try { oneMethod(); System.out.println("condition 1"); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("condition 2"); } catch(Exception e) { System.out.println("condition 3");
A.condition 1
B.condition 2
C.condition 3
D.condition 1 finally
10.下面程序的輸出結(jié)果是什么? class Happy { public static void main(String args[]) { int i =1; int j = 10; do { if ( i++ < j--) continue; } while ( i <5 ); System.out.println ( i+" "+j ); } }
A.5 5
B.5 4
C.6 4
D.5 6
11.下面程序的輸出結(jié)果是什么? class Foo{ static void change(String s){ s=s.replace('j','l'); } public static void main(String args[]){ String s="java"; change(s); System.out.println(s); } }
A.lava
B.java
C.編譯錯(cuò)誤
D.運(yùn)行時(shí)出現(xiàn)異常
12.下列語(yǔ)句序列執(zhí)行后,k 的值是( )。 int x=6, y=10, k=5; switch( x%y ) { case 0: k=x*y; case 6: k=x/y; case 12: k=x-y; default: k=x*y-x; }
A.60
B.54
C.0
D.5
13.下面的代碼段中,執(zhí)行之后i 和j 的值是什么? int i = 1; int j; j = i++;
A.1, 1
B.1, 2
C.2, 1
D.2, 2
14.下面的語(yǔ)句的作用是:( )。 Vector MyVector = new Vector(100,50);
A.創(chuàng)建一個(gè)數(shù)組類對(duì)象MyVector,有100個(gè)元素的空間,每個(gè)元素的初值為50。
B.創(chuàng)建一個(gè)向量類對(duì)象MyVector,有100個(gè)元素的空間,每個(gè)元素的初值為50。
C.創(chuàng)建一個(gè)數(shù)組類對(duì)象MyVector,有100個(gè)元素的空間,若空間使用完時(shí),以50個(gè)元素空間單位遞增。
D.創(chuàng)建一個(gè)向量類對(duì)象MyVector,有100個(gè)元素的空間,若空間使用完時(shí),以50個(gè)元素空間單位遞增。
15.給定下面的類: public class Example{ String str=new String(“good”); char ch[]={'a','b','c'}; public static void main(String args[]){ Example ex=new Example(); ex.change(ex.str,ex.ch); System.out.println(ex.str+”and”+ex.ch); } public void
A.good and abc
B.good and gbc
C.test ok and abc
D.test ok and gbc
16.下面程序的輸出結(jié)果是什么? public static void main(String args[]) { int a=10; int b=20; if(a=b) System.out.println("Not Equal"); else System.out.println("Equal"); }
A.Equal
B.Not Equal
C.編譯錯(cuò)誤
D.運(yùn)行時(shí)將拋出異常
17.請(qǐng)選擇以下代碼的正確的重載構(gòu)造器。 class Happy { Happy() { } }
A.public void Happy(){}
B.public Happy(int c){}
C.protected Happy(){}
D.void Happy(){}
18.65. 已知有下列類的說(shuō)明,則下列哪個(gè)語(yǔ)句是正確的? public class Test { private float f = 1.0f; int m = 12; static int n=1; public static void main(String arg[]) { Test t = new Test(); } }
A.t.f;
B.this.n;
C.Test.m;
D.Test.f;
19.若a的值為3時(shí),下列程序段被執(zhí)行后,c的值是多少?( ) c = 1; if ( a>0 ) if ( a>3 ) c = 2; else c = 3; else c = 4;
A.1
B.2
C.3
D.4
20.下列程序的功能是在監(jiān)控臺(tái)上每隔一秒鐘顯示一個(gè)字符串“Hello”,能夠填寫在程序中下劃線位置,使程序完整并能正確運(yùn)行的語(yǔ)句是 public class Test implements Runnable{ public static void main(String args[]){ Test t=new Test(); Thread tt=new Thread(t); tt.start(); } public void run(){ for(;;){ try{
A.sleep(1000) InterruptedException
B.sleep(1000) RuntimeException
C.Thread.sleep(1000) RuntimeException
D.Thread.sleep(1000) InterruptedException
二、多選題 (共 10 道試題,共 40 分)
21.已知如下代碼: switch (m) { case 0: System.out.println("Condition 0"); case 1: System.out.println("Condition 1"); case 2: System.out.println("Condition 2"); case 3: System.out.println("Condition 3");break; default: System.out.println("Other Condition"); } 當(dāng)m 的
A.0
B.1
C.2
D.3
E.4
F.以上都不是
22.String s=”Example String”; 下面哪些語(yǔ)句是正確的?
A.s>>>=3;
B.int i=s.length();
C.s[3]=”x”;
D.String short_s=s.trim();
E.String t=”root”+s;
23.已知如下類定義: class Base { public Base (){ //... } public Base ( int m ){ //... } protected void fun( int n ){ //... } } public class Child extends Base{ // member methods } 如下哪句可以正確地加入子類中?
A.private void fun( int n ){ //...}
B.void fun ( int n ){ //... }
C.protected void fun ( int n ) { //... }
D.public void fun ( int n ) { //... }
24.已知如下類說(shuō)明: public class Test { private float f = 1.0f; int m = 12; static int n=1; public static void main(String arg[]) { Test t = new Test(); // 程序代碼… } } 如下哪個(gè)使用是正確的?
A.t.f
B.this.n
C.Test.m
D.Test.n
25.你怎樣從下面main()的調(diào)用中訪問(wèn)單詞“kiss”? java lyrics a kiss is but a kiss
A.args[0]
B.args[1]
C.args[2]
D.args[3]
E.args[4]
F.args[5]
26.假定文件名是“Fred.java”,下面哪個(gè)是正確的類聲明。
A.public class Fred{ public int x = 0; public Fred (int x){ this.x=x; } }
B.public class fred{ public int x = 0; public Fred (int x){ this.x=x; } }
C.public class Fred extends MyBaseClass{ public int x = 0; }
27.下面代碼執(zhí)行后的輸出是什么? outer: for(int i=0;i<3; i++) inner: for(int j=0;j<2;j++) { if(j==1) continue outer; System.out.println(j+ “ and “+i); }
A.0 and 0
B.0 and 1
C.0 and 2
D.1 and 0
E.1 and 1
F.1 and 2
G.2 and 0
H.2 and 1
I.2 and 2
28.已知如下代碼: public class Test { public static void main(String arg[]) { int i = 5; do { System.out.println(i); } while (--i>5) System.out.println("finished"); } } 執(zhí)行后的輸出結(jié)果包括什么?
A.5
B.4
C.6
D.finished
E.什么都不輸出
29.針對(duì)下面的程序,那些表達(dá)式的值是true? Class Aclass{ private long val; public Aclass(long v){val=v;} public static void main(String args[]){ Aclass x=new Aclass(10L); Aclass y=new Aclass(10L); Aclass z=y; long a=10L; int b=10; } }
A.a==b;
B.a==x;
C.y==z;
D.x==y;
E.a==10.0;
30.在如下源代碼文件Test.java中, 哪個(gè)是正確的類定義?
A.public class test { public int x = 0; public test(int x) { this.x = x; } }
B.public class Test{ public int x=0; public Test(int x) { this.x = x; } }
C.public class Test extends T1, T2 { public int x = 0; public Test (int x) { this.x = x; } }
D.public class