Add demo for using enum to create singleton

This commit is contained in:
2025-04-10 10:53:05 +08:00
parent a010745843
commit 4c5eb89e59
3 changed files with 64 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
package feature;
public class Book {
private String title;
private String author;
private int pages;
public Book(String title, String author, int pages) {
this.title = title;
this.author = author;
this.pages = pages;
}
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public int getPages() {
return pages;
}
@Override
public String toString() {
return "Book{" +
"title='" + title + '\'' +
", author='" + author + '\'' +
", pages=" + pages +
'}';
}
}