java编写一个book类
时间: 2023-12-14 12:35:52 浏览: 94
以下是一个简单的Java Book类的示例:
```java
public class Book {
private String title;
private String author;
private int year;
public Book(String title, String author, int year) {
this.title = title;
this.author = author;
this.year = year;
}
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 getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
}
```
这个类有三个私有成员变量:title(书名),author(作者)和year(出版年份),以及一个构造函数和三个getter和setter方法。您可以根据需要添加其他方法。
阅读全文