You are on page 1of 3

Assertions

FormoredetailsonSUNCertifications,visitJavaScjpDumps
Q:01Given:
8.publicclasstest{
9.publicstaticvoidmain(String[]a){
10.asserta.length==1
11.}
12.}
WhichtwowillproduceanAssertionError?(Choosetwo.)
A.javatest
B.javaeatest
C.javatestfile1
D.javaeatestfile1
E.javaeatestfile1file2
F.javaea:testtestfile1
Answer:B,E
Q:02Givenamethodthatmustensurethatitsparameterisnotnull:
11.publicvoidsomeMethod(Objectvalue){
12.//checkfornullvalue
...
20.System.out.println(value.getClass())
21.}
What,insertedatline12,istheappropriatewaytohandleanullvalue?
A.assertvalue==null
B.assertvalue!=null,"valueisnull"
C.if(value==null){
thrownewAssertionException("valueisnull")
}
D.if(value==null){
thrownewIllegalArgumentException("valueisnull")
}
Answer:D
Q:03Given:
23.intz=5
24.
25.publicvoidstuff1(intx){
26.assert(x>0)
27.switch(x){
28.case2:x=3
29.default:assertfalse}}
30.
31.privatevoidstuff2(inty){assert(y<0)}
32.

33.privatevoidstuff3(){assert(stuff4())}
34.
35.privatebooleanstuff4(){z=6returnfalse}
Whichstatementistrue?
A.Alloftheassertstatementsareusedappropriately.
B.Onlytheassertstatementonline31isusedappropriately.
C.Theassertstatementsonlines29and31areusedappropriately.
D.Theassertstatementsonlines26and29areusedappropriately.
E.Theassertstatementsonlines29and33areusedappropriately.
F.Theassertstatementsonlines29,31,and33areusedappropriately.
G.Theassertstatementsonlines26,29,and31areusedappropriately.
Answer:C
Question:04
ClicktheExhibitbutton.
1.publicclassTest{
2.
3.publicstaticvoidmain(String[]args){
4.booleanassert=true
5.if(assert){
6.System.out.println(assertistrue)
7.}
8.}
9.
10.}
Given:
javacsource1.3Test.java
Whatistheresult?
A.Compilationfails.
B.Compilationsucceedswitherrors.
C.Compilationsucceedswithwarnings.
D.Compilationsucceedswithoutwarningsorerrors.
Answer:C
05.Giventwofiles:
1.classOne{
2.publicstaticvoidmain(String[]args){
3.intassert=0
4.}
5.}
1.classTwo{
2.publicstaticvoidmain(String[]args){
3.assert(false)
4.}
5.}
Andthefourcommandlineinvocations:

javacsource1.3One.java
javacsource1.4One.java
javacsource1.3Two.java
javacsource1.4Two.java

Whatistheresult?(Chooseallthatapply.)
A.Onlyonecompilationwillsucceed.
B.Exactlytwocompilationswillsucceed.
C.Exactlythreecompilationswillsucceed.
D.Allfourcompilationswillsucceed.
E.Nocompilerwarningswillbeproduced.
F.Atleastonecompilerwarningwillbeproduced.
Answer:
>BandFarecorrect.ClassOnewillcompile(andissueawarning)usingthe1.3flag,
andclassTwowillcompileusingthe1.4flag.
>A,C,D,andEareincorrectbasedontheabove.(Objective2.3)
06.Whicharetrue?(Chooseallthatapply.)
A.Itisappropriatetouseassertionstovalidateargumentstomethodsmarkedpublic.
B.Itisappropriatetocatchandhandleassertionerrors.
C.ItisNOTappropriatetouseassertionstovalidatecommandlinearguments.
D.Itisappropriatetouseassertionstogeneratealertswhenyoureachcodethatshouldnotbe
reachable.
E.ItisNOTappropriateforassertionstochangeaprogramsstate.
Answer:
>C,D,andEarecorrectstatements.
>Aisincorrect.Itisacceptabletouseassertionstotesttheargumentsofprivatemethods.B
isincorrect.Whileassertionerrorscanbecaught,Sundiscouragesyoufromdoingso.

You might also like