Exam 1z0-829 All QuestionsBrowse all questions from this exam
Question 33

Given:

and the code fragment:

What is the result?

    Correct Answer: B

    The given code performs a sequence of operations on an enum `Desig` and includes a dropWhile operation followed by a switch-case statement. The Arrays.stream(Desig.values()).dropWhile(s -> s.equals(Desig.CMO)) part of the code is intended to skip over the elements of the `Desig` enum until it reaches an element that does not match `Desig.CMO`. However, since `Arrays.stream(Desig.values()).dropWhile(s -> s.equals(Desig.CMO))` is not stored or used subsequently, it does not affect the following switch statement. Thus, the switch statement uses `Desig.valueOf("CMO")`, leading to a direct match in the switch case with `CMO` and printing "Marketing". The dropWhile operation has no effect on the switch statement execution. Therefore, the code correctly falls through the cases from `CMO` onwards and prints "Marketing", "Finance", and "Technical" successively.

Discussion
james2033Option: A

package q33; import java.util.Arrays; public class Q33 { public static void main(String[] args) { Arrays.stream(Desig.values()).dropWhile(s -> s.equals(Desig.CMO)); switch (Desig.valueOf("CMO")) { case CEO -> System.out.println("Executive"); case CMO -> System.out.println("Marketing"); case CFO -> System.out.println("Finance"); case CTO -> System.out.println("Technical"); default -> System.out.println("UnDefined"); } } } // Result: // Marketing

xplorerpjOption: A

A is correct answer

supersquaxOption: A

A is correct, tested in online compiler.