JAVA题:编写一个Book类用于描述图书,要求如下:
展开全部
public class Book {
private String title ;
private String author;
private int sell;
public Book(){
}
public Book(String title,String author,int sell){
this.title=title;
this.author=author;
this.sell=sell;
}
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 getSell() {
return sell;
}
public void setSell(int sell) {
this.sell = sell;
}
public String toString() {
return "D [title=" + title + ", author=" + author + ", sell=" + sell
+ "]";
}
}
private String title ;
private String author;
private int sell;
public Book(){
}
public Book(String title,String author,int sell){
this.title=title;
this.author=author;
this.sell=sell;
}
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 getSell() {
return sell;
}
public void setSell(int sell) {
this.sell = sell;
}
public String toString() {
return "D [title=" + title + ", author=" + author + ", sell=" + sell
+ "]";
}
}
追问
"D [title=" + title + ", author=" + author + ", sell=" + sell
+ "]"
为什么D后面加的是中括号"[ ]',而不是小括号"( )"?
追答
toString()我改一下吧;
public String toString() {
return author+"著"+title+"售出"+sell+"本"
其实无论是中括号或者圆括号()都是无所谓的 因为只是一个字符串而已
这样就会显示 张三著gama语言售出100本 前提是author是张三 title是gama语言 sell是100
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询