Oracle Certified Professional Java Se 8 Programmer · Free Practice Question Medium

Question 21

Given code of Test.java file:

What will be the result of compiling and executing Test class?

  • A

    {Jack, 12000}
    {Lucy, 14400}

  • B

    {Jack, 10000}
    {Lucy, 12000}

  • C

    {Jack, 10000.0}
    {Lucy, 12000.0}

  • D

    {Jack, 12000.0}
    {Lucy, 14400.0}

Reveal correct answer

Correct answer: D

Explanation

Iterator<T> interface has forEach(Consumer) method. As Consumer is a Functional Interface and it has 'void accept(T t)' method, hence a lambda expression for 1 parameter can be passed as argument to forEach(...) method.


'e -> e.setSalary(e.getSalary() + (e.getSalary() * .2))' => increments the salary of all the employees by 20%. 

'System.out::println' => prints employee object on to the console. 


As salary is of double type, so decimal point (.) is shown in the output.

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.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need