[Free] Download New Updated (October 2016) Oracle 1Z0-808 Real Exam 31-40

Ensurepass

QUESTION 31

Which of the following can fill in the blank in this code to make it compile?

 

clip_image002

 

A.

abstract

B.

public

C.

default

D.

It will not compile with any as interfaces cannot have non abstract methods.

E.

It will compile without filling the blank.

 

Correct Answer: C

Explanation:

From Java SE 8, we can use static and/or default methods in interfaces, but they should be non abstract methods. SO in this case using default in blank is completely legal. Hence option C is correct.

Option A is incorrect as given method is not abstract, so can’t use abstract there. Options B and E are incorrect as we can’t have non abstract method interface if they are not default or static.

https;//docs.oraclexom/javase/tutorial/java/Iandl/defaultmethods.html

 

 

QUESTION 32

Given:

 

clip_image004

 

What is the result?

 

A.

Red 0

Orange 0

Green 3

B.

Red 0

Orange 0

Green 6

C.

Red 0

Orange 1

D.

Green 4

E.

Compilation fails

Correct Answer: E

 

 

QUESTION 33

Given:

 

public class MyClass {

 

public static void main(String[] args) {

 

while (int ii = 0; ii < 2) {

 

ii++;

 

System.out.println(“ii = ” + ii);

 

}

 

}

 

}

 

What is the result?

 

A.

ii = 1

ii = 2

B.

Compilation fails

C.

The program prints nothing

D.

The program goes into an infinite loop with no output

E.

The program goes to an infinite loop outputting:

ii = 1

ii = 1

 

Correct Answer: B

Explanation:

The while statement is incorrect. It has the syntax of a for statement.

The while statement continually executes a block of statements while a particular condition is true. Its syntax can be expressed as:

 

while (expression) {

statement(s)

}

 

The while statement evaluates expression, which must return a boolean value. If the expression evaluates to true, the while statement executes the statement(s) in the while block. The while statement continues testing the expression and executing its block until the expression evaluates to false.

 

Reference: The while and do-while Statements

 

 

 

 

 

 

QUESTION 34

Given the code fragment:

 

clip_image006

 

What is the result?

 

A.

A B C Work done

B.

A B C D Work done

C.

A Work done

D.

Compilation fails

 

Correct Answer: C

 

 

QUESTION 35

Given the classes:

 

* AssertionError

 

* ArithmeticException

 

* ArrayIndexOutofBoundsException

 

* FileNotFoundException

 

* IllegalArgumentException

 

* IOError

 

* IOException

 

* NumberFormatException

 

* SQLException

 

Which option lists only those classes that belong to the unchecked exception category?

 

A.

AssertionError, ArrayIndexOutOfBoundsException, ArithmeticException

B.

AssertionError, IOError, IOException

C.

ArithmeticException, FileNotFoundException, NumberFormatException

D.

FileNotFoundException, IOException, SQLException

E.

ArrayIndexOutOfBoundException, IllegalArgumentException, FileNotFoundException

 

Correct Answer: A

Explanation:

Not B: IOError and IOException are both checked errors. Not C, not D, not E: FileNotFoundException is a checked error.

Note:

Checked exceptions:

* represent invalid conditions in areas outside the immediate control of the program (invalid user input, database problems, network outages, absent files)

* are subclasses of Exception

* a method is obliged to establish a policy for all checked exceptions thrown by its implementation (either pass the checked exception further up the stack, or handle it somehow)

 

Note:

Unchecked exceptions:

* represent defects in the program (bugs) – often invalid arguments passed to a non-private method. To quote from The Java Programming Language, by Gosling, Arnold, and Holmes:

“Unchecked runtime exceptions represent conditions that, generally speaking, reflect errors in your program’s logic and cannot be reasonably recovered from at run time.”

* are subclasses of RuntimeException, and are usually implemented using IllegalArgumentException, NullPointerException, or IllegalStateException

* method is not obliged to establish a policy for the unchecked exceptions thrown by its implementation (and they almost always do not do so)

 

 

QUESTION 36

Given:

 

clip_image008

 

What would be the output, if it is executed as a program?

 

A.

name =, pass =

B.

name = null, pass = null

C.

name = null, pass = false

D.

name = null pass = true

E.

Compile error.

 

Correct Answer: C

Explanation:

Both name and pass variables are instance variables, and we haven’t given them any values, so they take their default values. For Boolean default value is false and for string which is not a primitive type default is null So at line 7, null will printed as the value of the variable name, and at line 8 false will be printed. Hence Option C is correct. As explained above options A, B and D are incorrect.

Code compiles fine so option E is incorrect.

 

Reference:

https://docs.oracle.com/javaseAutorial/java/javaOOAariables.html

 

 

QUESTION 37

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

 

clip_image010

 

A.

long

B.

double

C.

int

D.

float

E.

byte

 

Correct Answer: BD

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.

 

 

QUESTION 38

Which three statements describe the object-oriented features of the Java language?

 

A.

Objects cannot be reused.

B.

A subclass can inherit from a superclass.

C.

Objects can share behaviors with other objects.

D.

A package must contain more than one class.

E.

Object is the root class of all other objects.

F.

A main method must be declared in every class.

 

Correct Answer: BCE

 

 

 

 

QUESTION 39

Given the code fragment:

 

clip_image012

 

What is the result?

 

A.

Element 0

Element 1

B.

Null element 0

Null element 1

C.

Null

Null

D.

A NullPointerException is thrown at runtime.

 

Correct Answer: D

 

 

QUESTION 40

Given the code fragment:

 

clip_image014

 

Which two modifications should you make so that the code compiles successfully?

 

clip_image016

 

A.

Option A

B.

Option B

C.

Option C

D.

Option D

E.

Option E

 

Correct Answer: AC

Explanation:

Add throws clause in both printFileContent and main.

 

Free VCE & PDF File for Oracle 1Z0-808 Real Exam

Instant Access to Free VCE Files: CompTIA | VMware | SAP …
Instant Access to Free PDF Files: CompTIA | VMware | SAP …

This entry was posted in Uncategorized and tagged , . Bookmark the permalink.