Complete the code to define a simple Response DTO class with a message field.
public class ResponseDTO { private String [1]; public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } }
The field name should be message to match the getter and setter methods.
Complete the code to add a constructor that sets the message field.
public ResponseDTO([1] String message) {
this.message = message;
}The constructor parameter type must be String to match the message field type.
Fix the error in the toString method to correctly return the message.
@Override
public String toString() {
return [1];
}The toString() method should return the message by calling the getter getMessage() to follow good practice.
Fill both blanks to create a ResponseDTO with a message and return it from a controller method.
@GetMapping("/hello") public ResponseDTO sayHello() { return new ResponseDTO([1]); } // The message to return is [2]
The controller returns a new ResponseDTO with the message "Hello, World!".
Fill all three blanks to create a ResponseDTO with a message, status, and data fields.
public record ResponseDTO([1] String message, [2] int status, [3] Object data) {}
private or final which are not valid in record components.static which is not allowed for record components.In a Java record, the components are implicitly public. Explicitly using public is correct here.