所以我有三个课程:书籍,书籍和Allbooks.booksout和Allbooks是扩展/是书籍的子类.但是我有一个问题/疑问:
我在toString方法中从allBooks得到一个错误.说bookID等(即书中的所有变量)都设置为私有.我被告知你应该总是尽量避免公共变量,所以我犹豫不决.还有另外一种方法吗?或者将它们公之于众是最简单/最好的方式来处理这个问题?
这是代码:
图书
public class books {
private int bookID;
private String title;
private String author;
public books() {
}
public books(int bookID, String title, String author) {
this.bookID = bookID;
this.title = title;
this.author = author;
}
public int getBookID() {
return bookID;
}
public void setBookID(int bookID) {
this.bookID = bookID;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void …Run Code Online (Sandbox Code Playgroud)