Oracle Certified Professional Java Se 11 Developer · Free Practice Question Hard
Question 40
Question ID: UKOCP16131
F: is accessible for reading/writing and below is the directory structure for F:
- F:.
- └───Parent
- │ a.txt
- │ b.txt
- │
- └───Child
- c.txt
- d.txt
Given code of Test.java file:
- package com.udayankhattry.ocp;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Path;
- import java.nio.file.Paths;
- import java.nio.file.attribute.BasicFileAttributes;
- import java.util.function.BiPredicate;
- public class Test {
- public static void main(String[] args) throws IOException {
- var root = Paths.get("F:");
- BiPredicate<Path, BasicFileAttributes> predicate = (p,a) -> p.endsWith(null);
- try(var paths = Files.find(root, 2, predicate))
- {
- paths.forEach(System.out::println);
- }
- }
- }
What will be the result of compiling and executing Test class?
- A Above program executes successfully and prints nothing on to the console
-
B
Above program executes successfully and prints below lines on to the console:
F:Parent\a.txt
F:Parent\b.txt
-
C
Above program executes successfully and prints below lines on to the console:
F:Parent\Child\c.txt
F:Parent\Child\d.txt
F:Parent\a.txt
F:Parent\b.txt
- D Compilation error
Reveal correct answer
Correct answer: D
Explanation
UKOCP16131:
endsWith method is overloaded in Path interface:
boolean endsWith(Path other);
boolean endsWith(String other);
p.endsWith(null) causes compilation error as it is an ambiguous method call.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
