25
https://www.certification-questions.com/ 1Z0-808 PDF Oracle 1Z0-808 PDF is available. Enrolling now you will get access to 308 unique 1Z0-808 certification questions at: https://www.certification-questions.com/java8-free-pdf-download/1Z0-808-pdf.html This is a sample demo for 1Z0-808: Q1. Given 1. class Test{ 2. 3. public static void main(String[] args){ 4. 5. int []a = {1,2,3,4,5,6}; 6. int i = a.length; 7. 8. while(i>=1){ 9. System.out.print(a[i]); 10. i--; 11. } 12. } 13. } What would be the output, if it is executed as a program? A. 123456 B. 65432 C. 12345 D. An exception could be thrown at runtime. E. Compile error. D is correct. Length of array “a” is 6, so the value of the variable i is 6. Execution of while loop will try to print array element reverse as variable “i” has initial value 6 , So trying to access element with index position 6 will cause ArrayIndexOutOfBoundsException since the array positions start with0. Hence the correct option is D.

1Z0 808-pdf

Embed Size (px)

Citation preview

Page 1: 1Z0 808-pdf

https://www.certification-questions.com/

1Z0-808PDF

Oracle 1Z0-808 PDF is available.

Enrolling now you will get access to 308 unique 1Z0-808 certification questions at: https://www.certification-questions.com/java8-free-pdf-download/1Z0-808-pdf.html

This is a sample demo for 1Z0-808:

Q1.Given

1. classTest{2. 3. publicstaticvoidmain(String[]args){4. 5. int[]a={1,2,3,4,5,6};6. inti=a.length;7. 8. while(i>=1){9. System.out.print(a[i]);10. i--;11. }12. }13. }

Whatwouldbetheoutput,ifitisexecutedasaprogram?

A. 123456

B. 65432

C. 12345

D. Anexceptioncouldbethrownatruntime.

E. Compileerror.

Discorrect.

Lengthofarray“a”is6,sothevalueofthevariableiis6.Executionofwhileloopwilltrytoprintarrayelementreverseasvariable“i”hasinitialvalue6,Sotryingtoaccesselementwithindexposition6willcauseArrayIndexOutOfBoundsExceptionsincethearraypositionsstartwith0.HencethecorrectoptionisD.

Page 2: 1Z0 808-pdf

https://www.certification-questions.com/

Examobjective: Using Loop Constructs - Create and use while loops

Creating and Using Arrays - Declare, instantiate, initialize and use a one-dimensional array

Q2.Given

1. classEx6{2. publicstaticvoidmain(Stringargs[]){3. inti=0,j=10; 4. try{5. j/=i;6. }7. System.out.print("DividebyZero!");8. catch(Exceptione){9. System.out.print(“error”);10. }11. } 12. }

Whatistheoutput?

A. 0

B. 0DividebyZero!

C. DividebyZero!Error

D. Error

E. Compilationfails.

F. Anuncaughtexceptionisthrownatruntime.

OptionEiscorrect.

Youcan’tentercodebetweentryandcatchclause.Hereline7causesthefailure.SotheanswerisE,ifyouremoveline7thencodewillcompilefineandprovideoutputaserrorsointhatcaseanswerwouldbeD.

Examobjective: Handling Exceptions - Create a try-catch block and determine how exceptions alter normal program flow

Page 3: 1Z0 808-pdf

https://www.certification-questions.com/

Q3.Consider

• AandEareClasses• BandDareinterfaces• Cisanabstractclass

Whicharetrue?(Choose3)

A. classFimplementsB,C{}

B. classFimplementsB{}

C. classFextendsA,E{}

D. classFextendsE{}

E. classFimplementsB,D{}

B,DandEarecorrect.

Wecanusethekeyword“extends”toextendeithertwoclassesortwointerfaces.Inclassitdoesn’tmatterwhetherabstractornot.Wecanusethekeyword“implements”toimplementaninterfacetoaclass.Multipleinterfacescanbeimplementedbyclassorinterfacebutnotmultipleclasses.SoB,DandEarecorrectaccordingtofollowingreasons.

Aisincorrectaswetriedtoimplementanabstractclass,buttheabstractclassshouldbeextended.Cisincorrectaswecan’textendmorethanoneclassinjava.

Examobjective: Working with inheritance – implement inheritance

Page 4: 1Z0 808-pdf

https://www.certification-questions.com/

Q4.Given

1. classTest{

2. publicstaticvoidmain(String[]args){

3. inta[]={};

4. System.out.print(ainstanceofObject);

5. }

6. }

Note:Thekeyword“instanceof”isusetocheckwhetheranobjectisofaparticulartype

Whichistrue?

A. Willproduceoutputasfalse.

B. Compilationfailsduetoerroratline3.

C. Willproduceoutputastrue.

D. Compilationfailsduetoerroratline4.

E. Lengthofthisarrayis3.

Ciscorrect.

CodewillcompilefinesoCiscorrect.ItproducetrueastheoutputasarrayistypeofobjectsoitreturnstruesotheanswerCiscorrectandAisincorrect.

Examobjective: Creating and Using Arrays - Declare instantiate, initialize and use a one-dimensional array.

Page 5: 1Z0 808-pdf

https://www.certification-questions.com/

Q5.Given

1. classProgram{

2. staticIntegeri;

3. publicstaticvoidmain(String[]args){

4. try{

5. System.out.println(i.compareTo(0));

6. }catch(ArithmeticException|NullPointerExceptione){

7. System.out.println("Exception");

8. }

9. }

10. }

Whichistheoutput?

A. -1

B. 0

C. 1

D. Exception

E. Compilationfails.

OptionDiscorrect.

Fromjavase8,wecanusecatchboxformultiexceptionssothiscodecompilesfine.IngivencatchboxitcancatchbothArithmeticExceptionandNullPointerException.Atline7,aNullPointerExceptionwillbethrownsinceIisnotinitialized.HenceoptionDiscorrect.

Examobjective:HandlingExceptions-Createatry-catchblockanddeterminehowexceptionsalternormalprogramflow

Page 6: 1Z0 808-pdf

https://www.certification-questions.com/

Q6.Given

1. classEx1{

2. publicstaticvoidmain(String[]args){

3. inta[]={1,2,053,4};

4. intb[][]={{1,2,4},{2,2,1},{0,43,2}};

5. System.out.print(a[3]==b[0][2]);

6. System.out.print(""+(a[2]==b[2][1]));

7. }

8. }

Whichistheoutput?

A. truefalse

B. falsefalse

C. falsetrue

D. truetrue

E. Compilationfails

Discorrect.

Indexingofarrayelementsbeginwithzero.So[1]referstothesecondelementofanarray.Soherea[3]referstothefourthelementofarraya.It’svalueis4andwehaveassigned4tob[0][2].Wehaveassignedoctalvaluetoa[2]sothevalueofelementis43indecimals.Andwehaveassigned43indecimaltob[2][1].Sobothwillprinttrue

AccordingtoabovereasonsA,BandCareincorrect.Eisincorrectascodecompilesfine.

Examobjective: Creating and Using Arrays - Declare instantiate, initialize and use a one-dimensional array.

Declare, instantiate, initialize and use multi-dimensional array

Page 7: 1Z0 808-pdf

https://www.certification-questions.com/

Q7.Choosethreelegalidentifiers.

A. 2ndtName

B. _8_

C. &name

D. $

E. new

BandDarecorrect.

Identifierscanstartwithaletter,adollarmarkoranunderscore.Theycanhaveanylength.Itisgoodpracticetodefineidentifiersmeaningfullynotlikehereasitwillmakeeasytoreadyoucodewhenreviewneeded.Alsowecan’tuseanyreservedkeywordforvariablename.HenceEisincorrectas“new”isreservedkeyword.

Aisincorrectasitstartswithanumber.

Cisincorrectasitstartwith“&”.

Examobjective: Working With Java Data Types - Declare and initialize variables

Page 8: 1Z0 808-pdf

https://www.certification-questions.com/

Q8.Given

1. classTest{

2. intvalue=10;

3. publicstaticvoidmain(String[]args){

4. newTest().print();

5. }

6. publicvoidprint(){

7. intvalue=8;

8. System.out.print(value);

9. }

10. }

Whichistheoutput?

A. 8

B. 10.

C. Compilationfailsduetoerroratline4.

D. Compilationfailsduetoerroratline7.

Aiscorrect.

Insideaclassmethod,whenalocalvariablehavethesamenameasoneoftheinstancevariable,thelocalvariableshadowstheinstancevariableinsidethemethodblock.Sothevalueof“a”(8)inmethodprint()canseeastheoutput.SotheanswerisA.

Bisincorrectastheinstancevariableisshadowedbythevariableinthemethodprint().

Thecodecompilesfine,henceCandDareincorrect.

Examobjective: Java Basics - Define the scope of variables

Page 9: 1Z0 808-pdf

https://www.certification-questions.com/

Q9.Given

1. classTest{

2. staticintx=0;

3. publicstaticvoidmain(String[]args){

4. for(intx=0;x<5;x++){ }

5. System.out.print(x);

6. }

7. }

Whichistheoutput?

A. 4

B. 5

C. 0

D. Compilationfails.

E. Runtimeexceptionwillbethrown.

Ciscorrect.

ThelifeofVariablexendswiththeendofforloopasthescopeofvariablexlimitswithinforloop.Sothevalueofstaticvariablewillprint.Sotheoutputwillbe0.HencetheanswerisC.

AandBareincorrectasexplainedabove.

Thereisnoreasontofailthecompilationortothrowexception,sotheCandEareincorrect.

Examobjective: Java Basics - Define the scope of variables

Page 10: 1Z0 808-pdf

https://www.certification-questions.com/

Q10.Given

1. classExer{

2. publicstaticvoidmain(String[]args){

3. Strings="Java";

4. s.concat("SE7");

5. s.replaceAll(“7”,””);

6. System.out.print(s);

7. }

8. }

Whatistheresult?

A. JavaSE“”

B. JavaSE7

C. JavaSE

D. Java.

E. Compilationfails.

Discorrect.

LinethreecreateanewStringobjectandgivesitthevalue“Java”.LinefourandfivemodifiedtheString“java”butthereisnoreferenceusedtoreferthatmodifiedobjects.SoitreallycreatestwouselessStringobjects.Soattheendsstaysas“Java”.

SotheA,BandCareincorrectasthe“Strings”remainsunchangedasexplainedabove.

Examobjective: Working With Java Data Types - Create and manipulate strings

Page 11: 1Z0 808-pdf

https://www.certification-questions.com/

Q11.Whicharetrue?

A. Defaultconstructorshouldbealwaysthereforanyclass.

B. Defaultconstructoronlycontains“this();”.

C. Whendefiningourownconstructorwecan’tuseanyaccessmodifier.

D. Aconstructorshouldnothaveareturntype.

E. Wecan’tchangedefaultconstructorofaninterface.

Discorrect.

WecanuseanyaccessmodifierConstructor,soCisincorrect.Eisincorrectasinterfacesdonothaveconstructors.

Aisincorrectaswhenthereisuserdefinedconstructor,thedefaultconstructorvanishsoitisnotamust,howeveratleastoneconstructorshouldpresent.

Bisincorrectasdefaultconstructorhas“super();”.

Examobjective: Working with Methods and Encapsulation - Differentiate between default and user-defined constructors

Page 12: 1Z0 808-pdf

https://www.certification-questions.com/

Q12.Considerfollowingthreestatements

I.Overloadedmethodmustchangetheargumentlist.

II.Overloadedmethodmaychangethereturntype.

III.Overloadedmethodmaydeclarebroadercheckedexception.

Whichistrue?

A. Ionly

B. IIonly

C. IIIonly

D. IandIIonly

E. all

Eiscorrect

AnswerisEcorrectasallgivenstatementsarecorrect.

StatementIiscorrectasoverloadedmethodmustchangetheargumentlist.

StatementIIiscorrectasoverloadedmethodsmaychangethereturntype.

StatementIIIiscorrectastheycanthrowneworbroaderexceptions.

Examobjective:WorkingwithMethodsandEncapsulation–Create an overloaded method

Page 13: 1Z0 808-pdf

https://www.certification-questions.com/

Q13.Given

1. classSup{2. protectedvoidmethod(intx){3. System.out.print("Sup"+x);4. }5. }6. classSubextendsSup{7. //overloadmethod()here8. }

Consider

I. publicvoidmethod(){}

II. privatefinalintmethod(inti){returni;}

III. privatefinalvoidmethod(Strings)throwsException{}

Whichistrue?

A. Ionly

B. IIonly

C. IandIIIonly

D. IandIIonly

E. all

Ciscorrect.

IIisincorrectsincetherewehaven’tchangetheargumentlist,whichisamustforanoverloading.

IandIIIarecorrectastherewehavechangedtheargumentlist,overloadedmethodcanchangethereturntype.alsocanthrowneworbroaderexceptions.

Examobjective:WorkingwithMethodsandEncapsulation–Create an overloaded method

Page 14: 1Z0 808-pdf

https://www.certification-questions.com/

Q14.Considerfollowingmethod

publicvoidmethod(inta){

}

Whichistrue?

A. Thismethodcanonlyinvokethroughaninstanceofenclosingclass.

B. Thismethodhasmarkedwithhighestrestrictiveaccessmodifier.

C. Thismethodreturnsanint.

D. Thismethodtakesintarrayasargument.

E. Thisisanincorrectmethod.

Aiscorrect

Givenmethodisdeclaredwithpublicaccesslevelwhichisthelowestrestrictiveaccesslevel.Sincewehaveusedvoid,methodcan’treturnanything.Methodtakesintegerasanargument.Alsotherewehaven’tusestatic,soitmeansitisaninstancemethod,soyouhavetohaveainstanceofenclosingclasstoaccessthatmethod,henceoptionAiscorrect.

Examobjective:WorkingwithMethodsandEncapsulation–Create methods with arguments and return values.

Page 15: 1Z0 808-pdf

https://www.certification-questions.com/

Q15.Considerfollowingmethod

staticintmin(double[]in){

//codes

}

Whichistrue?

A. Thismethodisincorrectasitdoesn’thaveaccessmodifier.

B. Thismethodhasmarkedwithstaticaccessmodifier.

C. Thismethodcanbeusedtoreturntheminimumvalueofanarray.

D. Noneofabove.

Discorrect

Aisincorrectaseverymethodshouldhaveaccesslevel,inthiscasewehaven’tusedanyaccessmodifierexplicitlysoitwillbeautomaticallydefaultaccesslevel.

Bisincorrectasstaticisnotanaccessmodifier.Cisincorrectasthismethodtakedoublearrayastheargumentandreturninteger,sincetheminimumvalueofthearrayisdouble,wecan’tusethismethodforthetask.

Examobjective:WorkingwithMethodsandEncapsulation–Create methods with arguments and return values.

Page 16: 1Z0 808-pdf

https://www.certification-questions.com/

Q16.Given

1. classTest{2. publicstaticvoidmain(Stringargs[]){3. finalintj;4. j=2;5. intx=0;6. 7. switch(x){8. case0:{System.out.print("A");}9. case1:System.out.print("B");break;10. casej:System.out.print("C");11. }12. }13. }

Whatistrue?

A. TheoutputcouldbeA

B. TheoutputcouldbeAB

C. TheoutputcouldbeABC

D. Compilationfails.

E. Therecouldbenooutput

Discorrect.

Whenusingswitch,casevariableshouldbeacompiletimeconstant.

Discorrectasthiscodefailstocompileasthe"casej"s"j"isnotcompiletimeconstant.(Hereintegerjisnotacompiletimeconstant.)Otheranswersareincorrectasthiscodefailstocompile.

Examobjective: Using Operators and Decision Constructs – Use switch statements

Page 17: 1Z0 808-pdf

https://www.certification-questions.com/

Q17.Given

1. classTest{2. publicstaticvoidmain(Stringin[]){3. int[]in={1,2,3};4. for(intx=0;++x<4;x++)5. System.out.print(in[x]);6. }7. }

Whatistheoutput?

A. 123

B. 2followedbyanArrayIndexOutOfBoundsException

C. 23

D. Compilationfails.

E. NooutputandArrayIndexOutOfBoundsExceptionwillbethrownatruntime

Discorrect.

Itisillegaltohavetwovariableswithsamenameinsideonescope.Inthiscasemethodargumentisdeclaredwithnameinandalsoatline3,thereisanothervariabledeclaredwithnamein,whichcausesacompiletimeerror.

Examobjective:JavaBasics-Definethescopeofvariables

Page 18: 1Z0 808-pdf

https://www.certification-questions.com/

Q18.Given

1. classTest{2. publicstaticvoidmain(Stringargs[]){3. intx=(int)args[0];4. System.out.print(x);5. }6. }

Whatistrue?

A. Ifweusecommandlineinvocation,javaTest5,theoutputwillbe5.

B. Ifweusecommandlineinvocation,javaTestabc,AnClassCastExceptionwillbethrown.

C. Ifweusecommandlineinvocation,javaTest,aArrayIndexOutOfBoundsExceptionwillbethrown.

D. Compilationfailsduetoerroronline3.

E. Compilationfailsduetomultipleerrors

Discorrect.

DiscorrectasJavacompileralreadyknowssomeinconvertibletypes.HerewetrytoconvertaStringtoint,itcauseacompileerrorandnotClassCastException.CodefailssoEisincorrect.Thiscodefailstocompilesoitwon’tproduceanyoutputorexceptionsoA,BandCareincorrect.Thiscodefailstocompilesoitwon’tproduceanyoutputorexceptionsoA,BandCareincorrect.

ExamObjective:Workingwithinheritance–Determinewhencastingisnecessary.

Handling Exceptions - Differentiate among checked exceptions, RuntimeExceptions and Errors

Page 19: 1Z0 808-pdf

https://www.certification-questions.com/

Q19.Whichiscorrect?

A. Lowcohesionisbetter.

B. Loosecouplingisbad.

C. Highcohesionmakesiteasiertomaintainprogram.

D. Tightcouplingmakesiteasiertomaintainprogram.

Ciscorrect.

Couplingisthedegreethatoneclassknowsaboutanother.Asanexample,ifclassAknowsmorethanitshouldabouttheclassBthenwhathappenswhenwemodifyBwithoutknowingClassA,thenitmayaltertheClassAtoo.SohighcouplingisnotgoodsoBisincorrect.

Cohesionisusedtoindicatethedegreetowhichaclasshassingle,wellfocusedpurpose.Solowcohesionclassmakeithardertomaintainasitsupportsmultipleunfocusedroles.SoCiscorrectandAisincorrect.

ExamObjective:Working with methods and encapsulation–Applyencapsulationprinciplestoaclass

Page 20: 1Z0 808-pdf

https://www.certification-questions.com/

Q20.Given

1. classOCAJP{2. publicstaticvoidmain(String[]args){3. intx=10;4. inty=x>10?1:x<10?-1:0;5. System.out.println(y);6. }7. }

Whatistheresult?

A. 1

B. -1

C. 10

D. 0

E. Compilationfails.

Discorrect.

Herewehavecombinedtwoternaryoperators.Firstonechecklocalvariablexisgreaterthan10ifnotthenitdoanothercomparisontocheckiflocalvariablexislesserthan10,otherwiseitwillassign1tothevariabley.Ifsecondconditionmetthenitwillassign-1tothevariabley,ifnotthen0willbeassignedtothevariabley,sointhiscase0willbeassignedtothevariabley.HenceoptionDiscorrect.

ExamObjective:UsingOperatorsandDecisionConstructs-Createifandif/elseandternaryconstructs

Page 21: 1Z0 808-pdf

https://www.certification-questions.com/

Q21.Whichofthefollowingiscorrectlambdaexpression?

A. Predicate<String>filter=()->{returnc.indexOf("a")>0;};

B. Predicate<String>filter=(c)->returnc.indexOf("a")>0;

C. Predicate<String>filter=(c)->{returnc.indexOf("a");};

D. Predicate<String>filter=(c)->{returnc.length();};

Aiscorrect.

Alambdaexpressioniscomposedofthreeparts.

ArgumentList ArrowToken Body

Thebodycanbeeitherasingleexpressionorastatementblock.Intheexpressionform,thebodyissimplyevaluatedandreturned.Intheblockform,thebodyisevaluatedlikeamethodbodyandareturnstatementreturnscontroltothecalleroftheanonymousmethod.ButrememberreturnstatementisNOTanexpressionsoinalambdaexpression,youshouldenclosestatementsinbraces({...}).Alsoyoucanomitthedatatypeoftheparametersinalambdaexpression.

PredicatetestmethodreturnsaBooleansoCandDareincorrect.

Bisincorrectastherewehaven’tusecurlybraces.

ExamObjective:Working with Selected classes from the Java API –WriteasimpleLambdaexpressionthatconsumesaLambdaPredicateexpression

Page 22: 1Z0 808-pdf

https://www.certification-questions.com/

Q22.Given

1. //Assumeallnecessaryimportinghavedone2. 3. publicclassTest{4. 5. publicstaticvoidmain(String[]args){6. 7. ArrayList<String>list=newArrayList<String>();8. list.add("A");9. list.add("B");10. list.add("C");11. list.add("D");12. 13. Instantstart=Instant.now();14. 15. list.forEach((s)->System.out.println(s));16. 17. Instantend=Instant.now();18. 19. longduration=//inserthere20. }21. }

Whichinsertatline19,willassigntotalexecutiontimeofline13inmillisecondstothedurationvariable?

A. newDuration(start,end).getMillis());

B. end-start

C. Duration.between(start,end);

D. Duration.between(start,end).toMillis();

OptionDiscorrect.

OptionDiscorrectasDurationmeasuresanamountoftimeusingtime-basedvalues.Here,togettotalexecutiontime,wecahusetwojava.Time.Intantinstances.Wecaninvokethestatic“between”methodofjava.time.Durationclass,whichwillreturndurationobjectwithtimedifference.ToconvertittomillisecondsweusetoMills()method.

OptionAisincorrectasthereisnosuchaconstructorwhichtakestwoInstantobjectsforDurationclass.

OptionBisincorrectaswecan’tdosuchoperationdirectlywithInstantinstances.

OptionCisincorrectasdirectresultofthebetweenmethodisinISOformat,notinmilliseconds,forexample,Itwouldresultsomethinglike“PT0.252S”.

EXAMOBJECTIVE : Working with Selected classes from the Java API - Create and manipulate calendar data using classes from java.time.LocalDateTime, java.time.LocalDate, java.time.LocalTime, java.time.format.DateTimeFormatter, java.time.Period

Page 23: 1Z0 808-pdf

https://www.certification-questions.com/

Q23.Considerfollowinginterface.

interfaceMulti{ publicintmultiply(intp1,intp2);

}

Whichofthefollowingwillcreateinstanceofaboveinterfacetype?(Chose2)

A. Multimul=(x,y)->returnx*y;

B. Multimul=(x,y)->{returnx*y;};

C. Multimul=()->{returnx*y;};

D. Multimul=(intx,inty)->{returnx*y;};

E. Multimul=(intx,inty)->returnx*y;

F. Multimul=()->returnx*y;

OptionBandDarecorrect.

HereweuselambdaexpressionforconcretingabstractmethodofMultiinterface.Alambdaexpressioniscomposedofthreeparts.

ArgumentList ArrowToken Body

Thebodycanbeeitherasingleexpressionorastatementblock.Intheexpressionform,thebodyissimplyevaluatedandreturned.Intheblockform,thebodyisevaluatedlikeamethodbodyandareturnstatementreturnscontroltothecalleroftheanonymousmethod.ButrememberreturnstatementisNOTanexpressionsoinalambdaexpression,youMUSTenclosestatementsinbraces({...}).Alsoyoucanomitthedatatypeoftheparametersinalambdaexpression.

Asexplainedabove,OptionAandEisincorrectasthereisnobraceswherereturnstatementpresent.

OptionCisincorrectasargumentsnotgiven.

ExamObjective:Working with Selected classes from the Java API –WriteasimpleLambdaexpressionthatconsumesaLambdaPredicateexpression

Page 24: 1Z0 808-pdf

https://www.certification-questions.com/

Q24.Given

1. importjava.util.List;2. importjava.util.ArrayList;3. classTest{4. publicstaticvoidmain(String[]args){5. Listlist=newArrayList(1);6. lst.add(5);7. lst.add("A");8. lst.add(newInteger(5));9. System.out.print(lst);10. }11. }

Whichistrue?

A. Theoutputwillbe[5,A,5]

B. Theoutputwillbe[]

C. Compilationfailsduetoerroronline5.

D. Compilationfailsduetomultipleerrors.

E. AnExceptionisthrownattheruntime

OptionAiscorrect.

OptionAiscorrectasthecodecompilesandrunswithoutanyexceptionandprints[1,A,5].

WehavenotspecifiedwhatcanListlistholds,soitcantakeanykindofobjectexceptprimitive.HenceitiscompletelylegaltoaddStringandInteger.

ExamObjective:WorkingwithSelectedclassesfromtheJavaAPI-DeclareanduseanArrayListofagiventype

Page 25: 1Z0 808-pdf

https://www.certification-questions.com/

Q25.Whichofthefollowingisacheckedexception?

A. FileNotFoundException

B. ArithmeticException

C. ClassCastException

D. NullPointerException

E. IllegalArgumentException

Aiscorrect.

ArithmeticException:ThrownbytheJVMwhencodeattemptstodividebyzero

ClassCastException:ThrownbytheJVMwhenanattemptismadetocastanexceptiontoasubclassofwhichitisnotaninstance

NullPointerExceptionThrownbytheJVMwhenthereisanullreferencewhereanobjectisrequired.

IllegalArgumentException:Thrownbytheprogrammertoindicatethatamethodhasbeenpassedanillegalorinappropriateargument

AboveallexceptionsareRuntimeexceptions.

FileNotFoundException:Thrownprogrammaticallywhencodetriestoreferenceafilethatdoesnotexist.Andthisischeckedexception.SooptionAiscorrect.

ExamObjective:Handling Exceptions –Differentiateamongcheckedexceptions,uncheckedexceptions,andErrors