阅读量:0
以下是一个使用Java的StatusInfo类的示例:
import java.util.Date; public class StatusInfo { private String message; private Date timestamp; private int statusCode; public StatusInfo(String message, int statusCode) { this.message = message; this.timestamp = new Date(); this.statusCode = statusCode; } public String getMessage() { return message; } public Date getTimestamp() { return timestamp; } public int getStatusCode() { return statusCode; } public static void main(String[] args) { StatusInfo statusInfo = new StatusInfo("Success", 200); System.out.println("Message: " + statusInfo.getMessage()); System.out.println("Timestamp: " + statusInfo.getTimestamp()); System.out.println("Status Code: " + statusInfo.getStatusCode()); } }
在上述示例中,我们定义了一个StatusInfo类,它有三个私有属性:message、timestamp和statusCode。我们使用构造函数初始化这些属性。然后,我们定义了几个getter方法来访问这些属性。
在main方法中,我们创建了一个StatusInfo对象,并使用getter方法打印出对象的属性值。输出结果如下:
Message: Success Timestamp: Sun Aug 29 11:34:52 CST 2021 Status Code: 200