Oracle: Question & Answers
Oracle: Question & Answers
1Z0-817
Upgrade OCP Java 6 & 7 & 8 to Java SE 11 Developer
QUESTION & ANSWERS
https://www.dumps4less.com/1Z0-817-dumps-pdf.html
QUESTION 1
Correct Answer: F
Explanation/Reference:
Four of the five examples print miny. Option C does not compile. The difference is that
partitioningBy() requires a Predicate that returns a boolean. When getting a question like this on the
exam, focus on the differences between the provided options.
QUESTION 2
https://www.dumps4less.com/1Z0-817-dumps-pdf.html
seaTurtle.swim(7);
}
}
A. 5
B. None of the above
C. The code does not compile.
D. 3
E. 7
F. 2
Correct Answer: C
Explanation/Reference:
The main() method attempts to define an anonymous class instance but fails to provide the class or
interface name, or use the new keyword. The right-hand side of the assignment to the seaTurtle
variable should start with new CanSwim(). For this reason,. If the code was corrected with the proper
declaration, then the program would output 7 at runtime.
QUESTION 3
Given the following two classes, each in a different package, which line inserted into the code allows
the second class to compile?
package commerce;
public class Bank {
public void withdrawal(int amountInCents) {}
public void deposit(int amountInCents) {}
}
package employee;
// INSERT CODE HERE
public class Teller {
public void processAccount(int deposit, int withdrawal) {
withdrawal(withdrawal);
deposit(deposit);
}
}
A. static import commerce.Bank;
B. import static commerce.Bank;
C. import static commerce.Bank.*;
D. static import commerce.Bank.*;
E. None of the above
https://www.dumps4less.com/1Z0-817-dumps-pdf.html
Correct Answer: E
Explanation/Reference:
A static import is used to import static members of another class. In this case, the withdrawal() and
deposit() methods in the Bank class are not marked static. They require an instance of Bank to be
used and cannot be imported as static methods. . If the two methods in the Bank class were marked
static, would be the correct answer since wildcards can be used with static imports to import more
than one method
QUESTION 4
Correct Answer: C
Explanation/Reference:
When replacing a variable in a subclass, Java uses the reference type to determine the variable to
use. Option A would be correct if the size variables were treated like method overriding since all of
the objects in the main() method are instances of Light. Instead, the reference type is used. The
variables v1 and v2 are of reference type Light, so 5 is selected. Likewise, the variable v3 is of type
Wave, so 7 is used. The output is 5,5,7, making option B correct.
https://www.dumps4less.com/1Z0-817-dumps-pdf.html
QUESTION 5
Correct Answer: A
Explanation/Reference:
Option A does not compile because Java does not allow declaring different types as part of the same
declaration. The other three options show various legal combinations of combining multiple variables
in the same declarations with optional default values.
QUESTION 6
A. One.
B. Two.
C. Three.
D. The code does not compile because of the DiskPlayer class.
E. The code does not compile for a different reason.
F. None of the above.
https://www.dumps4less.com/1Z0-817-dumps-pdf.html
Correct Answer: E
Explanation/Reference:
The code does not compile because john is declared in the try-with-resources statement and not
accessible in the finally block.
QUESTION 7
Fill in the blanks: The ___________________ keyword is used in method declarations, while the
___________________ keyword is used to send an exception to the surrounding process.
A. throwing, catch
B. throws, throw
C. catch, throw
D. throws, catch
E. throw, throws
F. catch, throwing
Correct Answer: B
Explanation/Reference:
The throws keyword is used in method declarations, while the throw keyword is used to send an
exception to the surrounding process, making option B the correct answer. The catch keyword is used
to handle exceptions. There is no throwing keyword in Java.
QUESTION 8
Which of the following can replace the body of the travel() method to produce the same output on any
nonempty input?
public void travel(List˂Integer˃ roads) {
for (int w = 1; w ˂= roads.size(); w++)
System.out.print(roads.get(w-1));
}
A. for (int q = roads.size(); q ˃= 0; q++) System.out.print(roads.get(q));
B. for(var z : roads) System.out.print(z);
C. for (var var : roads) System.out.print(roads);
D. None of the above
E. for (int t = roads.size(); t ˃ 0; t--) System.out.print(roads.get(t));
F. for (int r = 0; r ˂ roads.size(); r += 1) System.out.print(roads.get(0));
https://www.dumps4less.com/1Z0-817-dumps-pdf.html
Correct Answer: B
Explanation/Reference:
e method prints the elements of the list in the order in which they are defined.
QUESTION 9
Correct Answer: A
Explanation/Reference:
Lines 3 and 6 do not compile because wrapper classes are not permitted as annotation element
types. Line 5 does not compile because a constant must be declared with a value. For these reasons,
option D is correct. The rest of the lines compile without issue.
QUESTION 10
https://www.dumps4less.com/1Z0-817-dumps-pdf.html
Correct Answer: B
Explanation/Reference:
Options A and C print one line if numChipmunks is 1, 2, or 3. Option B does not behave the same way
if numChipmunks is 1 or 2. There is no break statement, so the case statements fall through, and
more than one statement will be printed.
QUESTION 11
Explanation/Reference:
Generally speaking, classes should be marked with the Serializable interface if they contain data that
we might want to save and retrieve later
QUESTION 12
A. 3
B. 2
C. The code does not compile.
D. The code compiles but throws an exception at runtime.
https://www.dumps4less.com/1Z0-817-dumps-pdf.html
E. 4
Correct Answer: B
Explanation/Reference:
First, determine whether the if statement’s expression is executed. The expression 8 >valuates to 2.
The right-hand side of the expression is evaluated next since + has a higher precedence than ˃. Since
2 ˃ 2 is false, the expression triceratops++ is not called. Notice there are no braces, {}, in the if
statement. Despite the triceratops–– line being indented, it is not part of the if statement. Therefore,
triceratops–– is always executed, resulting in a value of 2 for triceratops, and making option A the
correct answer.
QUESTION 13
A. 15
B. 25
C. 35
D. One line does not compile.
E. Two lines do not compile.
F. The program compiles but throws an exception at runtime.
Correct Answer: E
Explanation/Reference:
The first woof() method does not compile because bark is a primitive, not an object, and does not
https://www.dumps4less.com/1Z0-817-dumps-pdf.html
have a toString() method. The main() method also does not compile because it is static and all of the
woof() methods require an instance of Canine. Since these two lines do not compile, option E is the
correct answer. If the toString() was removed from the first method and all of the methods were
marked static, then the program would print 15 at runtime.
QUESTION 14
Which statements about the following class are correct? (Choose three.)
import java.security.*;
import java.util.*;
https://www.dumps4less.com/1Z0-817-dumps-pdf.html
Correct Answer: C,D,F
Explanation/Reference:
Caching permissions for a user is allowed, so option F is correct. That said, the security on using the
cached data must be checked. The class is missing calls to AccessController.checkPermission() before
lines h1 and h2. On line h1, this can result in a user reading a cached permission they do not have
access to, making option B correct. On line h2, security permissions could be elevated since access is
not checked,
QUESTION 15
Fill in the blanks: The name of the abstract method in the Function interface is ______________, while
the name of the abstract method in the Consumer interface is ______________
A. apply(), apply()
B. apply(), accept()
C. accept(), apply()
D. accept(), get()
E. apply(), test()
Correct Answer: B
Explanation/Reference:
The Function interface uses apply(), while the Consumer interface uses accept(), making . For
reference, get() is the name of the method used by Supplier, while test() is the name of the method
used by Predicate.
https://www.dumps4less.com/1Z0-817-dumps-pdf.html