Bird
0
0

What will be the HTTP status code returned by this code?

medium📝 component behavior Q5 of 15
Spring Boot - REST Controllers
What will be the HTTP status code returned by this code?
return ResponseEntity.notFound().build();
A404 Not Found
B200 OK
C500 Internal Server Error
D204 No Content
Step-by-Step Solution
Solution:
  1. Step 1: Understand notFound() method

    ResponseEntity.notFound() sets status to 404 Not Found.
  2. Step 2: build() returns ResponseEntity without body

    build() completes the response with the set status and no body.
  3. Final Answer:

    404 Not Found -> Option A
  4. Quick Check:

    notFound().build() = 404 status [OK]
Quick Trick: Use notFound().build() to return 404 without body [OK]
Common Mistakes:
  • Assuming 200 OK is default
  • Confusing build() with body()
  • Expecting a response body with notFound()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes