java定义一个图书类book
时间: 2023-09-14 10:10:04 浏览: 296
好的,以下是一个简单的Java图书类Book的定义:
```java
public class Book {
private String title;
private String author;
private int year;
private String isbn;
public Book(String title, String author, int year, String isbn) {
this.title = title;
this.author = author;
this.year = year;
this.isbn = isbn;
}
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;
}
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
}
```
在这个类中,我们定义了四个属性,分别是书名(title)、作者(author)、出版年份(year)和ISBN号(isbn)。我们还提供了一个构造函数和一些访问器(getter)和修改器(setter)方法来访问和修改这些属性。
阅读全文