javaee创建图书类
时间: 2023-08-28 14:19:38 浏览: 86
好的,以下是一个简单的JavaEE图书类的代码示例:
```java
public class Book {
private String title;
private String author;
private String publisher;
private int yearPublished;
private String isbn;
// 构造函数
public Book(String title, String author, String publisher, int yearPublished, String isbn) {
this.title = title;
this.author = author;
this.publisher = publisher;
this.yearPublished = yearPublished;
this.isbn = isbn;
}
// getter和setter方法
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 String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public int getYearPublished() {
return yearPublished;
}
public void setYearPublished(int yearPublished) {
this.yearPublished = yearPublished;
}
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
// toString方法
@Override
public String toString() {
return "Book [title=" + title + ", author=" + author + ", publisher=" + publisher + ", yearPublished="
+ yearPublished + ", isbn=" + isbn + "]";
}
}
```
该类包含了书籍的基本属性,其中有一个构造函数用于初始化该类,还包含了getter和setter方法用于访问和修改属性,最后还有一个toString方法用于返回该类的字符串表示形式。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)