java编写一个book类
时间: 2023-12-14 13:36:00 浏览: 77
book(IoC).zip_java 编写book类
5星 · 资源好评率100%
以下是一个简单的 Java Book 类的示例:
```java
public class Book {
private String title;
private String author;
private int pageCount;
private String publisher;
private String isbn;
public Book(String title, String author, int pageCount, String publisher, String isbn) {
this.title = title;
this.author = author;
this.pageCount = pageCount;
this.publisher = publisher;
this.isbn = isbn;
}
// Getters and Setters
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
}
```
这个 Book 类有五个属性,分别是书名、作者、页数、出版社和 ISBN 编号。它还包含一个构造函数和一些 Getter 和 Setter 方法,用于获取和设置属性。
阅读全文