1Z0-819 · Question #168
public interface EulerInterface { double getEulerValue(); } public class EulerLambda { public static void main(String[] args) { EulerInterface myEulerInterface = () -> 2.71828…
The correct answer is C. The code does not compile. Option C is correct because Java only permits one public type per .java source file. As written, both EulerInterface and EulerLambda are declared public - placing them in the same file violates this rule and the compiler rejects it immediately. Why the distractors are wrong: B…
Question
Options
- AIt throws a runtime exception.
- BValue of Euler = 2.71828
- CThe code does not compile.
- DValue of Euler = "2.71828"
How the community answered
(20 responses)- A10% (2)
- B5% (1)
- C80% (16)
- D5% (1)
Explanation
Option C is correct because Java only permits one public type per .java source file. As written, both EulerInterface and EulerLambda are declared public - placing them in the same file violates this rule and the compiler rejects it immediately.
Why the distractors are wrong:
- B is what would print if the code were fixed (e.g., split into two files or one declaration made package-private) - the lambda syntax itself is valid since
EulerInterfacequalifies as a functional interface (one abstract method), so() -> 2.71828is a legal implementation. - A is wrong because the error is a compile-time constraint, never reaching the JVM where a runtime exception could be thrown.
- D is wrong on two counts:
doublevalues don't print with quotes, and again, the code never runs.
Memory tip: When you see multiple public type declarations shown together in a single code block, always check the "one public type per file" rule before analyzing logic - it's a frequent gotcha on Java certification exams.
Topics
Community Discussion
No community discussion yet for this question.