Oracle Certified Professional Java Se 8 Programmer · Free Practice Question Hard
Question 15
Given code of Test.java file:
- package com.udayan.ocp;
- import java.util.function.Supplier;
- public class Test {
- public static void main(String[] args) {
- Supplier<StringBuilder> supplier = () -> new StringBuilder(" olleH")
- .reverse().append("!dlroW").reverse();
- System.out.println(supplier.get());
- }
- }
What will be the result of compiling and executing Test class?
- A >World! olleH<
- B > olleH!dlroW<
- C >Hello World!<
- D > olleHWorld!<
- E >World!Hello <
Reveal correct answer
Correct answer: A
Explanation
Syntax is correct and without any errors. Methods are chained from left to right.
new StringBuilder(" olleH") => " olleH"
" olleH".reverse() => "Hello "
"Hello ".append("!dlroW") => "Hello !dlroW"
"Hello !dlroW".reverse() => "World! olleH"
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
You must be logged in to post a comment.
