第 1 頁:試題 |
第 2 頁:參考答案 |
點擊查看:2018年3月計算機二級Java強化練習題及答案匯總
1.下列程序的輸出結果是()。
publicclassArrayTest
{
publicstaticvoidmain(Stringargs[])
{
int[]intArray=newint[3]
for(inti=0;i<3;i++)
{
intArray[i]=i+2:
system.out.println("lntArray["+i+"]¨=
intArray[i]);
}
System.out.println("----------");
intarrlen=4:
IntArray=newint[arrLen];
For(intj=intArray.length;j>=0;j--)
{
intArray[j]=j*3;
system.out.println("hello"+intArray[j]);
}
}
}
A.編譯未通過
B.編譯通過,但運行錯誤
C.可以運行,但有錯誤
D.以上都不對
2.下列程序的運行結果是()。
Publicclasssun
{
Publicstaticvoidmain(Stringargs[])
{
intx=4,y=0;
if(Math.pow(X,2)==16)
y—x;
if(Math.pow(X,2)<15)
y—l/x;
if(Math.pow(X,2)>15)
y=(int)Math.pow(X,2)+1;
system.out.println(y);
}
}
A.4
B.17
C.18
D.0.25
3.自定義的異常類可從()類繼承。
A.Error
B.AWTError
C.VirtualMachineError
D.Exception及其子集
4.t為int類型,進入下面的循環之前,t的值為0。則下列說法中正確的是()。while(t=1){…}
A.循環控制表達式的值為0
B.循環控制表達式的值為1
C.循環控制表達式不合法
D.以上說法都不對
5.下面for循環語句的執行結果是()。
for(intj=10;j>3;j--)
if(j1=O)
j--;
--j;
--j;
System.OUt.println(j);
}
A.63
B.74
C.62
D.73
6.關于Applet執行的操作,下面說法正確的是()。
A.在運行時調用其他程序
B.可以進行文件讀/寫操作
C.不能裝載動態連接庫和調用任何本地方法
D.試圖打開一個socket進行網絡通信,但是所連接的主機并不是提供Applet的主機
7.下列關于Applet生命周期的說法,正確的是()。
A.voidinit()在Applet下載前調用
B.voidstart()只在初始化之后調用
C.voidstop()在關閉瀏覽器時調用
D.stop()總在voiddestroy()之前被調用
8.對于下面語句的說法,不正確的是()。ThreadthrObj=newThread():
A.系統沒有為該線程對象分配資源
B.只能啟動或者終止
C.創建了一個空的線程對象
D.可以調用其他方法
9.在Java中,線程是()。
A.分時的
B.搶占式的
C.非搶占式的
D.非分時的
10.下列關于線程和進程的說法正確的是()。
A.進程結構的所有成分都在用戶空間內
B.用戶程序能夠直接訪問進程涉及的數據
C.線程是內核級的實體
D.線程結構駐留在用戶空間中
11.下列選項成員變量聲明正確的是()。
A.publicprotectedfinalinti;
B.abstractclassFl{…}
C.privatedoubleheight;
D.doubleweight()
12.下面程序段的輸出結果是()。
classTest{
publics,taticvoidmain(Stringargs[]){
MyThreadt=newMyThread();
t.displayOutput("thasbeencreateD");
t.start();
}
}
ClassMyThreadextendsThread{
publicvoiddisplayOutput(Strings){
System.out.println(s);
}
publicvoidrun(){
displayOutput("tisrunning.");
}
}
A.thasbeencreated.
B.thasbeencreated.tisrunning.
C.tisrunning.
D.編譯出錯
13.執行下列程序時,會產生什么異常()。
publicclassTest{
publicstaticvoidmain(Stringargs[]){
intd=101;
intb=220:
longa=321;
System.OUt.println((a-b)/(a-b-d));
}
}
A.ArraylndexOutOfBoundsException
B.NumberFormatException
C.ArithmeticException
D.EOFExeeption
14.下面程序段的輸出結果為()。
publicclassTest
{
publicstaticvoidmain(Stringargs[])
{
booleana,b,C;
a=(3<5):
b=(a==true);
System.out.println("a="+a+"b="+b);
c=(b==false);
System.out.println("b="+b+"c="+c);
}
}
A.a=trueb=falseB.fl=trueb=false
b=truec=trueb=truec=false
C.a=trueb=trueD.a=falseb=false
b=truec=falseb=truec=false
15.下面程序段的輸出結果是()。
publicclassTest{
publicstaticvoidmain(Stringargs[]){
inta,b;
for(a=1,b=1;a<=100;a++){
if(b>=10)break;
if(b%2==1){
b+=2:
continue;
}
}
System.OUt.println(a);
}
}
A.5B.6
C.7D.101
16.棧中允許進行插入和刪除的一端稱為()。
A.棧頂B.棧底
C.棧端D.棧尾
17.下面程序段的輸出結果是()。
publicclassTest{
publicstaticvoidmain(Stringargs[]){
inti=1:
switch(i){
case0:
System.OUt.println("0");
break;
casel:
System.out.println("1");
case2:
System.OUt.println("2");
break;
default:
System.out.println("default");
}
}
}
A.01
B.12
C.10
D.21
18.Frame默認的布局管理器是()。
A.FlowLayout
B.BorderLayout
C.GridLayout
D.UpLayout
19.在Java語言中,ObjectOutputStream是指()。
A.字節流
B.字符流
C.對象輸出流
D.數據流
20.請閱讀下列程序代碼,然后將程序的執行結果補充完整。橫線處應填寫的內容是()。
程序代碼:
publicclassthrowsExeeption{
staticvoidProc(intsel)
throwsArithmeticException,ArrayIndexOutOf
BoundsException{
System.out.println("InSituation"+sel);
if(sel==0){
System.OUt.println("noExceptioncaught");
return;
}
elseif(sel==l){
intiArray[]=newint[4];
iArray[1]=3;
}
}
publicstaticvoidmain(Stringargs[]){
try{
Proe(O);
Proc(1);
}
catch(ArrayIndexOutOfBoundsExceptione){
System.out.println("Catch"+e);
}
finally{
System.out.println("inProcfinally"):
}
}
}
執行結果:
InSituation0
noExceptioncaught
inProcfinally
A.InSituationl
B.InSituation
C.withCatch
D.intiArrayl
微信搜索"考試吧"了解更多考試資訊、下載備考資料
相關推薦: