Add demo for using enum to create singleton
This commit is contained in:
35
src/main/java/feature/Book.java
Normal file
35
src/main/java/feature/Book.java
Normal 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 +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user