1z0-808 | Update Oracle 1z0-808 vce


Q31. Given the code fragment: 

Which three code fragments can be independently inserted at line nl to enable the code to print one? 

A. Byte x = 1; 

B. short x = 1; 

C. String x = "1"; 

D. Long x = 1; 

E. Double x = 1; 

F. Integer x = new Integer ("1"); 

Answer: A,B,F 

Q32. Given: 

public class Test { 

public static void main(String[] args) { 

int arr[] = new int[4]; 

arr[0] = 1; 

arr[1] = 2; 

arr[2] = 4; 

arr[3] = 5; 

int sum = 0; 

try { 

for (int pos = 0; pos <= 4; pos++) { 

sum = sum + arr[pos]; 

} catch (Exception e) { 

System.out.println("Invalid index"); 

System.out.println(sum); 

What is the result? 

A. 12 

B. Invalid Index 

C. Invalid Index 

D. Compilation fails 

Answer:

Explanation: The loop ( for (int pos = 0; pos <= 4; pos++) { ), it should be pos <= 3, causes an exception, which is caught. Then the correct sum is printed. 

Q33. Given: 

And the commands: 

Javac Jump.java 

Java Jump crazy elephant is always 

What is the result? 

A. Lazy lion is jumping 

B. Lion is always jumping 

C. Crazy elephant is jumping 

D. Elephant is always jumping 

E. Compilation fails 

Answer:

Q34. Which statement best describes encapsulation? 

A. Encapsulation ensures that classes can be designed so that only certain fields and methods of an object are accessible from other objects. 

B. Encapsulation ensures that classes can be designed so that their methods are inheritable. 

C. Encapsulation ensures that classes can be designed with some fields and methods declared as abstract. 

D. Encapsulation ensures that classes can be designed so that if a method has an argument MyType x, any subclass of MyType can be passed to that method. 

Answer:

Q35. Given: 

What will be the output? 

A. Option A 

B. Option B 

C. Option C 

D. Option D 

Answer:

Q36. 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 

Answer: A,C,E 

Q37. Given the code fragment: 

And given the requirements: 

. If the value of the qty variable is greater than or equal to 90, discount = 0.5 

. If the value of the qty variable is between 80 and 90, discount = 0.2 

Which two code fragments can be independently placed at line n1 to meet the requirements? 

A. Option A 

B. Option B 

C. Option C 

D. Option D 

E. Option E 

Answer: A,C 

Q38. Given the code fragment: 

Which code fragment, when inserted at line n1, enables the App class to print Equal? 

A. Option A 

B. Option B 

C. Option C 

D. Option D 

Answer:

Q39. Given: 

What is the result? 

A. 10:20 

B. 0:20 

C. Compilation fails at line n1 

D. Compilation fails at line n2 

Answer:

Q40. Which of the following data types will allow the following code snippet to compile? 

A. long 

B. double 

C. int 

D. float 

E. byte 

Answer: B,D 

Explanation: 

Option B and D are the correct answer. 

Since the variables I and j are floats, resultant will be float type too. So we have to use float 

or primitive type which can hold float, such a primitive type is double, it has wider range 

and also can hold floating point numbers, hence we can use double or float for the blank. 

As explained above options B and D are correct. 

long and int can't be used with floating point numbers so option A is incorrect. 

Option E is incorrect as it have smaller range and also can't be used with floating point 

numbers. 

hnpsy/docs.oracle.com/javase/tutorial/java/javaOO/variables.html