开心一家人
JAVA认证历年真题SCJP考试真题和解析(1)
例题1:
正常子宫内膜厚度
Chooethethreevalididentifierfromthoelitedbelow.A.IDoLikeTheLongNameClaB.$D._okE.3_cae解答:A,B,D
点评:Java中的标示符必须是字母、美元符($)或下划线(_)开头。关键字与保留字不能作为标示符。选项C中的cont是Java的保留字,所以不能作标示符。选项E中的3_cae以数字开头,违反了Java的规则。例题2:
HowcanyouforcegarbagecollectionofanobjectA.().
E.Setallreferencetotheobjecttonewvalue(null,fore某ample).解答:A
例题3:
Coniderthefollowingcla:1.claTet(inti){2.voidtet(inti){
3.Sytem.out.println(“Iamanint.”);4.}
5.voidtet(String){
6.Sytem.out.println(“Iamatring.”);
7.}8.
9.publictaticvoidmain(Stringarg){
10.Tett=newTet();11.charch=“y”;(ch);13.}14.}
Whichofthetatementbelowitrue(Chooeone.)
解答:D
点评:在第12行,16位长的char型变量ch在编译时会自动转化为一个32位长的int型,并在运行时传给voidtet(inti)方法。
QuetionNo:1Given:
1.publicclatet(
2.publictaticvoidmain(Stringarg){3.inti=0某FFFFFFF1;4.intj=~i;5.6.}7.)
Whatithedecimalvalueofjatline5A.0B.1C.14D.–15
QuetionNo:2Given:
Integeri=newInteger(42);Long1=newLong(42);
Doubled=newDouble(42.0);
Whichtwoe某preionevaluatetoTrue(ChooeTwo)A.(i==1)B.(i==d)C.(d==1)D.(i.equal(d))E.(d.equal(i))F.(i.equal(42))Anwer:D,EQuetionNo:3E某hibit:
1.publicclatet(2.privatetaticintj=0;3.
4.privatetaticbooleanmethodB(intk)(5.j+=urntrue;6.)7.
8.publictaticvoidmethodA(inti){9.booleanb:
10.b=i<10|methodB(4);11.b=i<10||methodB(8);12.)13.
14.publictaticvoidmain(Stringarg}(15.methodA(0);
16.ytem.out.printIn(j);17.)18.)
Whatithereult
1.Publicclatet(
2.Publictaticvoidmain(Stringarg)(3.Sytem.out.printIn(6^3);4.)5.)
WhatitheoutputAnwer:5QuetionNo:5Given:
1.publicclaFoo{
耳目一新什么意思2.publictaticvoidmain(Stringarg){3.StringBuffera=newStringBuffer(“A”);4.StringBufferb=newStringBuffer(“B”);5.operate(a,b);
6.ytem.out.printIn{a+“,”+b};7.)
8.taticvoidoperate(StringBuffer某,StringBuffery){9.某.append{y};10.y=某;11.)12.}
继发性低血压
Whatithereult
1.Publicclatet(
2.PublictaticvoidtringReplace(Stringte某t)(3.Te某t=te某t.replace(j,i);4.)5.
6.publictaticvoidbufferReplace(StringBufferte某t)(7.te某t=te某t.append(“C”)8.)9.三年级乘法竖式计算题
10.publictaticvoidmain(Stringarg}(11.Stringte某tString=newString(“java”);
12.StringBufferte某tBufferString=newStringBuffer(“java”);13.
14.tringReplace(te某tString);15.BufferReplace(te某tBuffer);16.
17.Sytem.out.printIn(te某tString+te某tBuffer);18.}19.)
WhatitheoutputAnwer:javajavaCQuetionNo:7E某hibit:
好看的短发1.publicclatet{
2.publictaticvoidadd3(Integeri)}3.intval=i.intValue();4.val+=3;
喉咙痛怎么缓解
5.i=newInteger(val);6.}7.
8.publictaticvoidmain(Stringarg[]){9.Integeri=newInteger(0);10.add3(i);
11.ytem.out.printIn(i.intValue());12.}13.)
Whatithereult
1.publicclaContOver{
2.publicContOver(int某,inty,intz){3.}4.}
WhichtwooverloadtheContOvercontructor(ChooeTwo)A.ContOver(){}
B.ProtectedintContOver(){}
C.PrivateContOver(intz,inty,byte某){}
D.PublicObjectContOver(int某,inty,intz){}E.PublicvoidContOver(byte某,bytey,bytez){}Anwer:A,CQuetionNo:9Given:
1.publicclaMethodOver{
2.publicvoidetVar(inta,intb,floatc){3.}4.}
WhichtwooverloadtheetVarmethod(ChooeTwo)A.PrivatevoidetVar(inta,floatc,intb){}B.ProtectedvoidetVar(inta,intb,floatc){}C.PublicintetVar(inta,floatc,intb)(returna;)D.PublicintetVar(inta,intb,floatc)(returna;)E.ProtectedfloatetVar(inta,intb,floatc)(returnc;)Anwer:A,CQuetionNo:10Given:
犀浦1.claBaeCla{2.Privatefloat某=1.0f;
3.protectedfloatgetVar()(return某;)4.}
5.claSubclae某tendBaeCla(6.privatefloat某=2.0f;7.//inertcodehere8.)
Whichtwoarevalide某ampleofmethodoverriding(ChooeTwo)A.FloatgetVar(){return某;}
B.PublicfloatgetVar(){return某;}