Bird
0
0

Find the problem in this REST controller snippet:

medium📝 Debug Q7 of 15
Spring Boot - REST Controllers
Find the problem in this REST controller snippet:
@RestController
public class SampleController {
  @GetMapping("/info")
  public String info() {
    System.out.println("Info called");
  }
}
AIncorrect HTTP method annotation, should be @PostMapping
BMethod does not return any value but declared to return String
CMissing @RestController annotation
DClass must extend a base controller class
Step-by-Step Solution
Solution:
  1. Step 1: Check method return type and body

    The method declares it returns String but does not return anything, causing a compile error.
  2. Step 2: Review other options

    @RestController is present, @GetMapping is correct for GET requests, and extending a base class is not required.
  3. Final Answer:

    Method does not return any value but declared to return String -> Option B
  4. Quick Check:

    Declared return type must be returned [OK]
Quick Trick: Always return a value matching method signature [OK]
Common Mistakes:
  • Forgetting to return a value
  • Confusing HTTP method annotations
  • Thinking inheritance is mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes