Skip to content
Sharp

Core Java · interview question

How does the Optional class help in modern Java code?

Multiple choiceEasychapter-7-curatedpremiumcore-javacode-reading-with-modern-java
Choose one answer
Answer and explanation

Correct answer

B. Prevents NullPointerExceptions

Why

The Optional class provides a container that may or may not contain a value, allowing for cleaner and safer handling of nullable references without directly dealing with null checks.

Test yourself on Core Java

A free test with instant, explained results. No account needed.

Start free test
All Core Java questions →