英文 SCJP 模拟题200道附答案.docx
《英文 SCJP 模拟题200道附答案.docx》由会员分享,可在线阅读,更多相关《英文 SCJP 模拟题200道附答案.docx(48页珍藏版)》请在冰豆网上搜索。
![英文 SCJP 模拟题200道附答案.docx](https://file1.bdocx.com/fileroot1/2022-12/11/94e47bc8-df10-4aff-ab8e-19df75917f9c/94e47bc8-df10-4aff-ab8e-19df75917f9c1.gif)
英文SCJP模拟题200道附答案
SCJP模拟题200道附答案
Q1Whichofthefollowingstatementsarevalid,giventhefollowingvariabledeclarations:
booleana;booleanb;intc;
1)(a|b)
2)(a||a)
3)(a^b)|c
4)(a&c)
5)(a&&c)
Q2Whichofthefollowingcanbeappliedtoconstructors:
1)final
2)static
3)synchronized
4)native
5)Noneofthese.
Q3Whichofthefollowingretaintheirpreferredsize(widthandheight)whenadded(individually)totheNorthsectionofacontainerwithaBorderLayout(assumethatnoothercomponentsorcontainersarepresentintheNorthsection).
1)TextArea
2)Button
3)TextField
4)Checkbox
5)None.Allofthesementionedcomponentswillonlyretaintheirpreferredheight.
Q4Whichofthefollowingarelegalnamesforvariables.
1)_int
2)%large
3)$fred
4)Integer
5)2much
Q5Whichofthefollowingarecorrectwaystocreateafont.
1)Fontf=newFont("Serif",Font.BOLD,24);
2)Fontf=newFont(Font.SERIF,"Bold",24);
3)Fontf=newFont("Serif","Bold",24);
4)Fontf=newFont(Font.SERIF,Font.BOLD,24);
Q6Selectthecorrectstatementsregardingthefollowingpieceofcode.
Filef=newFile("c:
\\large.txt");
1)Onexecution,afilecalled"large.txt"willbecreatedonthelocalharddisk.
2)ThecodefailstocompileonaUNIXmachine,becausethedirectoryseparatorisnotcorrect.
3)AfileisNOTcreatedontheharddiskwhenthiscodeisexecuted.
4)Anexceptionisthrownatruntimeifthefile"large.txt"alreadyexists.
5)Thecodefailstocompile,sincethisisnotavalidconstructorfortheFileclass.
Q7WhichofthefollowingstatementsarecorrectregardingtheRandomAccessFileclass?
1)AnIOExceptionisthrownifthespecifiedfiledoesn'texistwhencreatedusingthe"r"mode.
2)Thisclasshasamethodwhichallowsafiletobedeletedfromtheharddisk.
3)ItispossibletousethisclassinconjunctionwiththeDataInputStreamclass.
4)Whenusedwiththe"rw"mode,thespecifiedfileiscreatedonadiskdrive,ifitdoesn'talreadyexist.
5)Therearemethodstoreadandwriteprimatives(eg,readInt(),writeInt(),etc).
Q8Considerthefollowingpieceofcodeandselectthecorrectstatementfromthefollowing.
1.Strings=newString("abcdefgh");
2.s.replace('d','q');
3.System.out.println(s);
1)Thecodefailstocompile,reportinganerroratline2.Stringsareimmutable,andthereforeareplace()methodismeaningless.
2)Thecodecompilescorrectly,anddisplaysthetext"abcqefgh".
3)Thecodecompilescorrectly,anddisplaysthetext"abcdefgh".
4)Thecodecompiles,butanexceptionisthrownwhenline2isexecuted.
5)Thecodecompiles,butanexceptionisthrownatline3.
Q9Whichofthefollowingkeywordscanbeappliedtothevariablesormethodsofaninterface.
1)static
2)private
3)synchronised
4)protected
5)public
Q10TrueorFalse.
OnlyFramescancontainmenubarsorpull-downmenus.
1)True
2)False.
Q11Considerthefollowingpieceofcodeandselectthecorrectstatement(s):
1.classA{
2.protectedintmethod(){
3.}
4.}
5.
6.classBextendsA{
7.intmethod(){
8.}
9.}
1)Thecodefailstocompile,becauseyoucan'toverrideamethodtobemoreprivatethanitsparent.
2)Thecodefailstocompile,becausemethod()isdeclaredasprotected,andisthereforenotavailabletoanysubclass.
3)Thecodecompilescorrectly,butthrowsaNullPointerExceptionatruntime.
4)Thecodefailstocompile.However,itcanbemadetocompilecorrectlybyprefixingline7withtheaccessqualifier"public".
5)Thecodefailstocompile.However,itcanbemadetocompilecorrectlybyprefixingline7withtheaccessqualifier"protected".
Q12TrueorFalse.
TheThrowableclassisthesuperclassofallexceptionsintheJavalanguage.
1)True
2)False
Q13Considerthefollowingpieceofcode(assumetheGraphicscontextgisdefinedcorrectly):
g.setBackground(Color.red);
g.setForeground(Color.white);
g.drawLine(10,10,50,10);
g.setForeground(Color.blue);
g.drawRect(100,100,50,50);
Whatisdisplayedwhenthiscodeisexecuted.
1)Abluelinefrom(10,10)to(50,10)andabluerectanglewithupperleftcornerat(100,100).
2)Awhitelinefrom(10,10)to(50,10)andabluesquarewithtopleftcornerat(100,100).
3)Awhitelinefrom(10,10)to(10,50)andabluesquarewithlowerleftcornerat(100,100).
4)Aredlinefrom(10,10)to(50,10)andaredsquarewithupperleftcornerat(100,100).
5)Nothingisdisplayed.Youmustfirstissuearepaint()command.
Q14Considerthefollowingpieceofcode.
classTest{
publicstaticvoidmain(String[]args){
System.out.println(args[3]);
}
}
Whenthefollowingistypedatthecommandline,whatisdisplayed:
javaTestMetallicaJusticeForAll
1)All
2)For
3)Justice
4)Nothing.
5)Nothing.AnArrayIndexOutOfBoundsExceptionisthrown
Q15Considerthefollowingpieceofcode.
1.Strings="abcd";
2.Integerx=newInteger(3);
3.Strings2=s+4;
4.s2=null;
5.s=null;
Followingtheexecutionofwhichlineabove,istheobjectreferencedbys2availableforgarbagecollection.
1)Line5
2)Itisnotpossibletosaywhenanobjectisavailableforgarbagecollection.
3)Line4
4)Theobjectsarenotavailableuntiltheexecutingthreadisended.
Q16Whatisdisplayedwhenthefollowingpieceofcodeiscompiledandexecuted:
classTest{
publicstaticvoidmain(String[]args){
Baseb=newSubclass();
System.out.println(b.x);
System.out.println(b.method());
}
}
classBase{
intx=2;
intmethod(){
returnx;
}
}
classSubclassextendsBase{
intx=3;
intmethod(){
returnx;
}
}
1)Nothing.Thecodefailstocompilebecausetheobjectbisnotcreatedinavalidway.
2)2
3
3)2
2
4)3
3
5)3
2
Q17Whatisdisplayedwhenthefollowingisexecuted:
Strings1="aaa";
s1.concat("bbb");
System.out.println(s1);
1)Thestring"aaa".
2)Thestring"aaabbb".
3)Nothing.concat()isnotavalidmethodintheStringclass.
4)Thestring"bbbaaa".
5)Thestring"bbb".
Q18TrueorFalse.
ThefollowingisavalidwaytoconstructaStringBuffer.
StringBuffersb1="abcd";
1)True
2)False
Q19Whatistheoutputofthefollowingpieceofcode:
1.intx=6;
2.doubled=7.7;
3.
4.System.out.println((x>d)?
99.9:
9);
1)9
2)9.0
3)99.9
4)Nothing.AnArithmeticExceptionisthrownatline4.
5)6
Q20Whichofthefollowingcanbeputinapplettags?
(selectallthecorrectanswers)
1)CODE
2)WIDTH
3)HEIGHT
4)PARAM
5)ARCHIVE
Q21Whatisprintedoutfollowingtheexecutionofthecodebelow:
1.classTest{
2.staticStrings;
3.publicstaticvoidmain(String[]args){
4.intx=4;
5.if(x<4)
6.System.out.println("Val="+x);
7.else
8.System.out.println(s);
9.}
10.}
Nothing.ThecodefailstocompilebecausetheStringsisn'tdeclaredcorrectly.
1)Thetext"Val=null"isdisplayed.
2)Thestring"Val="isdisplayed.
3)Thetext"null"isdisplayed.
4)Ablanklineoftextisprinted.
Q22TrueorFalse.
TheStringBufferclassdoesnothaveaconcat()method.
1)True
2)False
Q23Whatisdisplayedwhenthefollowingpieceofcodeisexecuted(assumethegraphicscontext,g,iscorrectlysetup):
g.drawString("abc",10,10);
1)Thetext"abc"withthelowerleftpartof"a"locatedatx=10,y=10.
2)Thetext"abc"withtheupperleftpartof"a"locatedatx=10,y=10.
3)Nothing.Thisisnotavalidmethod.
Q24TrueorFalse.
Anonymousclassescannothaveconstructors.
1)True
2)False
Q25ToreferenceaJARfromawebpage,whichofthefollowingkeywordsareused:
1)jar
2)class
3)zip
4)archive
5)package
Q26
Analysethefollowing2classesandselectthecorrectstatements.
classA{
privateintx=0;
staticinty=1;
protectedintq=2;
}
classBextendsA{
voidmethod(){
System.out.println(x);
System.out.println(y);
System.out.println(q);
}
}
1)ThecodefailstocompilebecausethevariablexisnotavailabletoclassB.
2)Thecodecompilescorrectly,andthefollowingisdisplayed:
012
3)Thecodefailstocompilebecauseyoucan'tsubclassaclasswithprivatevariables.
4)Removingtheline"System.out.println(x)"willallowthecodetocompilecorrectly.
5)ThecompilerwillcomplainthatthevariablexinclassBisundefined.
Q27Whichofthefollowinginterfacescanbeusedtomanageacollectionofelements,withnoduplication.
1)List
2)Vector
3)Set
Q28Whichofthefollowingstatementsaretrueregardinginnerclasses.
1)Variablesdefinedinsideinnerclassescannotbestatic.
2)Variablesdefinedinsideinnerclassescannotbestaticunlesstheinnerclassitselfisstatic.
3)Non-staticinnerclasses(whicharenotdefinedinamethod)haveaccesstoallclassandinstancevariables,regardlessoftheaccessqualifierofthosevariables.
4)Aninnerclasscanactuallybeasubclassoftheouterclass
5)Innerclassescanbedeclaredasprivate.Toplevel,outerclassescannot.
Q29Whichofthefollowingarevalidwaystodefineanabstractmethod.
1)abstractvoidTest();
2)abstractvoidTest(){}
3)staticabstractvoidTest();
4)finalabstractvoidTest();
5)Methodscannotbedefinedasabstract,onlyvariablescanbeabstract.
Q30Considerthefollowing:
classAextendsInteger{
intx=0;
}
Selectallvalidstatements.
1)Thecodewillcompilecorrectly.
2)ThecodewillnotcompilebecauseIntegerisfinalandcannotbesubclassed.
3)ThecodewillnotcompilebecauseclassAhasnomethodsorconstructor.
4)Thecodewillcompile