1z0-808 Practice Test Questions

236 Questions


Which three are advantages of the Java exception mechanism?


A.

Improves the program structure because the error handling code is separated from the
normal program function


B.

Provides a set of standard exceptions that covers all the possible errors


C.

Improves the program structure because the programmer can choose where to handle
exceptions


D.

Improves the program structure because exceptions must be handled in the method in
which they occurred


E.

Allows the creation of new exceptions that are tailored to the particular program being
created





A.
  

Improves the program structure because the error handling code is separated from the
normal program function



C.
  

Improves the program structure because the programmer can choose where to handle
exceptions



E.
  

Allows the creation of new exceptions that are tailored to the particular program being
created



Given the code fragment:

Which code fragment, when inserted at // insert code here, enables the code to compile
and and print a b c?


A.

List update (String[] strs)


B.

Static ArrayListupdate(String [] strs)


C.

Static List update (String [] strs)


D.

Static void update (String[] strs)


E.

ArrayList static update(String [] strs)





E.
  

ArrayList static update(String [] strs)



Given the following code:

What are the values of each element in intArr after this code has executed?


A.

15, 60, 45, 90, 75


B.

15, 90, 45, 90, 75


C.

15, 30, 75, 60, 90


D.

15, 30, 90, 60, 90


E.

15, 4, 45, 60, 90





C.
  

15, 30, 75, 60, 90



Given:

Which is true?


A.

Sum for 0 to 0 = 55


B.

 Sum for 0 to 10 = 55


C.

Compilation fails due to error on line 6.


D.

Compilation fails due to error on line 7.


E.

An Exception is thrown at the runtime.





D.
  

Compilation fails due to error on line 7.



Loop variables scope limited to that enclosing loop. So in this case, the scope of the loop
variable x declared at line 5, limited to that for loop. Trying to access that variable at line 7,
which is out of scope of the variable x, causes a compile time error. So compilation fails
due to error at line 7. Hence option D is correct.
Options A and B are incorrect, since code fails to compile.
Reference: httpsy/docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html

Given:
public class Test {
public static void main(String[] args) {
int ax = 10, az = 30;
int aw = 1, ay = 1;
try {
aw = ax % 2;
ay = az / aw;
} catch (ArithmeticException e1) {
System.out.println("Invalid Divisor");
} catch (Exception e2) {
aw = 1;
System.out.println("Divisor Changed");
}
ay = az /aw; // Line 14
System.out.println("Succesful Division " + ay);
}
}
What is the result?


A.

 Invalid Divisor
Divisor Changed
Successful Division 30


B.

 Invalid Divisor
Successful Division 30


C.

Invalid Divisor
Exception in thread "main" java.lang.ArithmeticException: / by zero
at test.Teagle.main(Teagle.java:14)


D.

 Invalid Divisor
Exception in thread "main" java.lang.ArithmeticException: / by zero
at test.Teagle.main(Teagle.java:14)
Successful Division 1





C.
  

Invalid Divisor
Exception in thread "main" java.lang.ArithmeticException: / by zero
at test.Teagle.main(Teagle.java:14)



int [] array = {1,2,3,4,5};
for (int i: array) {
if ( i < 2) {
keyword1 ;
}
System.out.println(i);
if ( i == 3) {
keyword2 ;
}}
What should keyword1 and keyword2 be respectively, in oreder to produce output 2345?


A.

A. continue, break


B.

reak, break


C.

break, continue


D.

continue, continue





D.
  

continue, continue



Given the code fragment
 


A.

Match 1


B.

Match 2


C.

No Match


D.

A NullPointerException is thrown at runtime





B.
  

Match 2



it will compare the string contents of the StringBuilder with string object.

Which statement will empty the contents of a StringBuilder variable named sb?


A.

sb.deleteAll();


B.

sb.delete(0, sb.size());


C.

sb.delete(0, sb.length());


D.

sb.removeAll();





C.
  

sb.delete(0, sb.length());



Given the code fragments:

Which code fragment, when inserted at line ni, enables the code to print Hank?


A.

checkAge (iList, ( ) -> p. get Age ( ) > 40);


B.

 checkAge(iList, Person p -> p.getAge( ) > 40);


C.

checkAge (iList, p -> p.getAge ( ) > 40);


D.

 checkAge(iList, (Person p) -> { p.getAge() > 40; });





C.
  

checkAge (iList, p -> p.getAge ( ) > 40);



Given:



A.

 Option A


B.

Option B


C.

Option C


D.

Option D





D.
  

Option D



Given the code fragment:
List colors = new ArrayList();
colors.add("green");
colors.add("red");
colors.add("blue");
colors.add("yellow");
colors.remove(2);
colors.add(3,"cyan");
System.out.print(colors);
What is the result?


A.

[green, red, yellow, cyan]


B.

[green, blue, yellow, cyan]


C.

[green, red, cyan, yellow]


D.

Am IndexOutOfBoundsException is thrown at runtime





A.
  

[green, red, yellow, cyan]



First the list [green, red, blue, yellow] is build.
The blue element is removed:
[green, red, yellow]
Finally the element cyan is added at then end of the list (index 3).
[green, red, yellow, cyan]

Given the code fragment:

What is the result?


A.

28false29
true


B.

285 < 429
true


C.

 true true


D.

compilation fails





C.
  

 true true




Page 8 out of 20 Pages
Previous