Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
Question Answer Points
1 A 8
2 A 8
3 E 8
4 D 8
5 20• 5for class• 10for main• 5points for
output
6 A 8
7 B 8
8 0 15
9 D 8
10 B 8
Question Answer Points
11 A 8
12 D 8
13 A 8
14 A 8
15 E 8
16 B 8
17 A 8
18 C 8
19 nextInt( 19)+22 20
• 10for21• 10for20
20 25
• 10forcorrectsubstring
• 10forcorrect calltolength()
• 5forcorrectoutput
Question1
ThelineofJavacode"//System.out.println("Hello");"will
• A)donothing• B)cause”Hello”tobeoutupt• C)cause asyntax error• D)cause“(Hello)”tobeoutput• E)thereisnowaytoknowwithoutexecutingthislineofcode
Question2
AuniqueaspectofJavathatallowscodecompiledononemachinetobeexecutedonamachineofadifferenthardwareplatformisJava’s• A)bytecodes• B)syntax• C)useofobjects• D)useofexceptionhandling• E)alloftheabove
Question2
Question3
Whichcharacterbelowisnotallowedinanidentifier?• A)$• B)_• C)0(zero)• D)q• E)^
Question4
Anerrorinaprogramthatresultsintheprogramoutputting$100insteadofthecorrectanswer,$250 is• A)Aprogrammererror• B)Asyntaxerror• C)Arun-timeerror• D)Alogical error• E)Asnafu
Question4
• B)Asyntaxerror• Compile Error
• C)Arun-timeerror• 12/0=?
• D)Alogicalerror• IncorrectAnswer
Question5
• WriteaJavaprogramthatwilldisplayontwoseparatelinesyournameandyourmajor.
Question5(GradingGuideline)
• 5pointsforhavingthekeywordclassandareasonableclassnameintherightplace• 2pointseachforstatic,void,main(),String[],args• 5pointsforoutput– thenameandthemajor
Question6
FollowingJavanamingconvention,whichofthefollowingwouldbethebestnameforaclassaboutstorecustomers?• A)StoreCustomer• B)StoreCustomer• C)storeCustomer• D)STORE_CUSTOMER• E)Store-Customer
Question7
Ifxisanint andyisadouble,allofthefollowingarelegalexceptwhichassignmentstatement?• A)y=(double)x;• B)x=y;• C)y=x;• D)x=(int)y;• E)alloftheabovearelegal
Question7
Ifxisanint andyisafloat,allofthefollowingarelegalexceptwhichassignmentstatement?• A)y=(double)x;• B)x=y;
• int <double• C)y=(float)x;• D)x=(int)y;• E)alloftheabovearelegal
Question8
• Whatwillbetheresultofainthefollowingassignmentstatement?Assumeb=8andc=10.
Question8(GradingGuideline)
• 15pionts• Upto10pointspartical creditiftheyhavesomecorrectwork
Question9
WhichlibrarypackagewouldyouimporttouseNumberFormat andDecimalFormat?• A)java.beans• B)java.io• C)java.lang• D)java.text• E)java.util
Question10
QuestionNineAndTen computes• A)Thecorrectaverageofx,yandzasadouble• B)Thecorrectaverageofx,yandzasanint• C)Theaverageofx,y,andzasadouble,buttheresultmaynotbeaccurate• D)Thesumofx,yandz• E)Theremainderofthesumofx,yandzdividedby3
Question11
Whatisoutputifx=0,y=1andz=1?• A)0• B)0.0• C)0.66666666• D)0.66666667• E)0.67
Question12
Inordertocreateaconstant,youwouldusewhichofthefollowingJavareservedwords?• A)private• B)static
• https://www.javatpoint.com/static-keyword-in-java
• C)int• D)final• E)class
Question13
InJava,avariablemaycontain• A)aprimitive valueoranobjectreference• B)apackage• C)amethod• D)aclass• E)anyoftheabove
Question14
Mistyping“println”as“printn”willresultin• A)Asyntaxerror• B)Aruntimeerror• C)alogicalerror• D)noerroratall• E)Convertingthestatementintoacomment
Question15
Whatisthefunctionofthedotoperator?• A)Itservestoseparatetheintegerportionfromthefractionalportionofafloatingpointnumber• B)Itallowsonetoaccessthedatawithinanobjectwhengivenareferencetotheobject• C)Itallowsonetoinvokeamethodwithinanobjectwhengivenareferencetotheobject• D)Itisusedtoterminatecommands(muchasaperiodterminatesasentenceinEnglish)• E)BothBandCarecorrect
Question16
InJava,”instantiation”means• A)noticingthefirsttimesomethingisused• B)creatinganewobjectoftheclass• C)creatinganewaliastoanexistingobject• D)launchingamethod• E)noneoftheabove
Question17
An“alias”when• A)Twodifferentreferencevariablesrefertothesamephysicalobject• B)Twodifferentnumericvariablesrefertothesamephysicalobject• C)Twodifferentnumericvariablescontainidenticalvalues• D)Twovariableshavethesamenames• E)noneoftheabove
Question18.
AnAPIis• A)anAbstractProgrammingInterface• B)anApplicationProgrammer’sInterface• C)anApplication ProgrammingInterface• D)anAbstractProgrammer’sInterface• E)anAbsoluteProgrammingInterface
Question19.
• Completethefollowingassignmentstatementthatgeneratesarandomnumberbetween22(inclusive)to40(inclusive).
Question20
• GivenaStringobject“ComputerScience”whoseobjectreferenceismajor,usetheobjectreferencetoinvokeproperStringinstancemethodstocreateasubstringcontaining“Sci”, calculatethelengthofthesubstring,displayboththesubstringanditslengthonthesameline.
Stringmajor=newString(“ComputerScience”);StringsubStringOfMajor;//Storethesubstringofmajorint lengthOfMajor;//Storethelengthofthesubstring
Question20
Question20(GradingGuideline)
25points• 10forcorrectsubstringcall
• takeoff5points ifthenumbersarenotcorrect
• 10forcorrectcalltolength()• 5forcorrectoutput:thesubstringandit’slengthmustbeonthesameline