编写book.java_编写一个javabean命名为:Book.java属性包括:
时间: 2024-02-20 18:00:13 浏览: 81
java代码-Book JavaBean
好的,下面是一个简单的 Book JavaBean,包括以下属性:
```java
public class Book {
private String title;
private String author;
private String publisher;
private int yearPublished;
private double price;
// 省略 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 double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
```
在这个 JavaBean 中,我们定义了五个属性:title、author、publisher、yearPublished 和 price。每个属性都有对应的 getter 和 setter 方法,用于读取和设置属性的值。
阅读全文