下面是一個使用Java的Video類的實例:
import java.util.Date;
public class Video {
private String title;
private String description;
private String url;
private Date uploadDate;
public Video(String title, String description, String url, Date uploadDate) {
this.title = title;
this.description = description;
this.url = url;
this.uploadDate = uploadDate;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public String getUrl() {
return url;
}
public Date getUploadDate() {
return uploadDate;
}
public void setTitle(String title) {
this.title = title;
}
public void setDescription(String description) {
this.description = description;
}
public void setUrl(String url) {
this.url = url;
}
public void setUploadDate(Date uploadDate) {
this.uploadDate = uploadDate;
}
public static void main(String[] args) {
Video video = new Video("Java Tutorial", "A tutorial on Java programming language", "https://www.youtube.com/watch?v=Hl-zzrqQoSE", new Date());
System.out.println("Title: " + video.getTitle());
System.out.println("Description: " + video.getDescription());
System.out.println("URL: " + video.getUrl());
System.out.println("Upload Date: " + video.getUploadDate());
video.setTitle("Java Video Tutorial");
System.out.println("New Title: " + video.getTitle());
}
}
這個例子創建了一個Video類,它有一個標題、一個描述、一個URL和一個上傳日期。我們使用構造函數來創建一個Video對象,并使用getter和setter方法來訪問和修改對象的屬性。在主方法中,我們創建了一個Video對象并打印出它的屬性。然后,我們使用setter方法修改標題,并再次打印出新的標題。