SCJP考题.docx
《SCJP考题.docx》由会员分享,可在线阅读,更多相关《SCJP考题.docx(199页珍藏版)》请在冰豆网上搜索。
SCJP考题
SCJP6.0認證教戰手冊黃彬華著碁峰出版
1
書名:
SCJP6.0認證教戰手冊作者:
黃彬華
完全擬真試題1-100(共244題)
第1題
Given:
35.String#name="JaneDoe";
36.int$age=24;
37.Double_height=123.5;
38.double~temp=37.5;
Whichtwostatementsaretrue?
(Choosetwo.)
A.Line35willnotcompile.
B.Line36willnotcompile.
C.Line37willnotcompile.
D.Line38willnotcompile.
答案:
AD
參考:
2-4Java程式內容簡介
第2題
Given:
1.publicclassTestString1{
2.publicstaticvoidmain(String[]args){
3.Stringstr="420";
4.str+=42;
5.System.out.print(str);
6.}
7.}
Whatistheoutput?
A.42
B.420
C.462
D.42042
E.Compilationfails.
F.Anexceptionisthrownatruntime.
答案:
D
參考:
3-3文字串接符號
第3題
Given:
1.publicclassTest{
2.publicstaticvoidmain(String[]args){
3.intx=5;SCJP6.0認證教戰手冊黃彬華著碁峰出版
2
4.booleanb1=true;
5.booleanb2=false;
6.
7.if((x==4)&&!
b2)
8.System.out.print("1");
9.System.out.print("2");
10.if((b2=true)&&b1)
11.System.out.print("3");
12.}
13.}
Whatistheresult?
A.2
B.3
C.12
D.23
E.123
F.Compilationfails.
G.Anexceptionisthrownatruntime.
答案:
D
參考:
4-1條件控制
第4題
Given:
22.publicvoidgo(){
23.Stringo="";
24.z:
25.for(intx=0;x<3;x++){
26.for(inty=0;y<2;y++){
27.if(x==1)break;
28.if(x==2&&y==1)breakz;
29.o=o+x+y;
30.}
31.}
32.System.out.println(o);
33.}
Whatistheresultwhenthego()methodisinvoked?
A.00
B.0001
C.000120
D.00012021
E.Compilationfails.
F.Anexceptionisthrownatruntime.
答案:
C
參考:
4-3特殊流程的處理
SCJP6.0認證教戰手冊黃彬華著碁峰出版
3
第5題
Given:
10.intx=0;
11.inty=10;
12.do{
13.y--;
14.++x;
15.}while(x<5);
16.System.out.print(x+","+y);
Whatistheresult?
A.5,6
B.5,5
C.6,5
D.6,6
答案:
B
參考:
4-2迴圈控制
第6題
Given:
1.publicclassBreaker{
2.staticStringo="";
3.publicstaticvoidmain(String[]args){
4.z:
5.o=o+2;
6.for(intx=3;x<8;x++){
7.if(x==4)break;
8.if(x==6)breakz;
9.o=o+x;
10.}
11.System.out.println(o);
12.}
13.}
Whatistheresult?
A.23
B.234
C.235
D.2345
E.2357
F.23457
G.Compilationfails.
答案:
G
參考:
4-3特殊流程的處理
第7題SCJP6.0認證教戰手冊黃彬華著碁峰出版
4
Given:
1.publicclassBreaker2{
2.staticStringo="";
3.publicstaticvoidmain(String[]args){
4.z:
5.for(intx=2;x<7;x++){
6.if(x==3)continue;
7.if(x==5)breakz;
8.o=o+x;
9.}
10.System.out.println(o);
11.}
12.}
Whatistheresult?
A.2
B.24
C.234
D.246
E.2346
F.Compilationfails.
答案:
B
參考:
4-3特殊流程的處理
第8題
Given:
1.publicclassSpock{
2.publicstaticvoidmain(String[]args){
3.Longtail=2000L;
4.Longdistance=1999L;
5.Longstory=1000L;
6.if((tail>distance)^((story*2)==tail))
7.System.out.print("1");
8.if((distance+1!
=tail)^((story*2)==distance))
9.System.out.print("2");
10.}
11.}
Whatistheresult?
A.1
B.2
C.12
D.Compilationfails.
E.Nooutputisproduced.
F.Anexceptionisthrownatruntime.
答案:
E
參考:
4-1條件控制SCJP6.0認證教戰手冊黃彬華著碁峰出版
5
第9題
Given:
11.String[]elements={"for","tea","too"};
12.Stringfirst=(elements.length>0)?
elements[0]:
null;
Whatistheresult?
A.Compilationfails.
B.Anexceptionisthrownatruntime.
C.Thevariablefirstissettonull.
D.Thevariablefirstissettoelements[0].
答案:
D
參考:
4-1條件控制、5-21維陣列介紹
第10題
Given:
1.importjava.util.*;
2.publicclassQuest{
3.publicstaticvoidmain(String[]args){
4.String[]colors=
5.{"blue","red","green","yellow","orange"};
6.Arrays.sort(colors);
7.ints2=Arrays.binarySearch(colors,"orange");
8.ints3=Arrays.binarySearch(colors,"violet");
9.System.out.print(s2+""+s3);
10.}
11.}
Whatistheresult?
A.2-1
B.2-4
C.2-5
D.3-1
E.3-4
F.3-5
G.Compilationfails.
H.Anexceptionisthrownatruntime.
答案:
C
參考:
5-41維陣列的排序與搜尋
第11題
Given:
1.classAlligator{
2.publicstaticvoidmain(String[]args){
3.int[]x[]={{1,2},{3,4,5},{6,7,8,9}};SCJP6.0認證教戰手冊黃彬華著碁峰出版
6
4.int[][]y=x;
5.System.out.print(y[2][1]);
6.}
7.}
Whatistheresult?
A.2
B.3
C.4
D.6
E.7
F.Compilationfails.
答案:
E
參考:
5-62維陣列的宣告與存取
第12題
DragandDrop(拖曳題)
AddmethodstotheBetaclasstomakeitcompilecorrectly.
classAlpha{
publicvoidbar(int...x){}
publicvoidbar(intx){}
}
publicclassBetaextendsAlpha{
Placehere
Placehere
Placehere
}
答案:
classAlpha{
publicvoidbar(int...x){}
publicvoidbar(intx){}
}
publicclassBetaextendsAlpha{
publicvoidbar(intx){}
publicintbar(Stringx){return1;}
publicvoidbar(intx,inty){}
}
參考:
6-5繼承
第13題
Given:
1