【发布时间】:2015-03-24 14:03:14
【问题描述】:
当我在 main 方法中调用 BookClass 时,状态的唯一输出是 true 或 false。
为什么它不会在我的 Setter 中打印出 if-else 语句?
public class Book {
private String title;
private int year;
private String author;
private boolean status;
public Book(String title, int year, String author, boolean status){
this.title = title;
this.year = year;
this.author = author;
this.status = status;
}
public void setStatus(boolean status){
this.status = status;
if(status){
System.out.println("Unavailable");
}
else{
System.out.println("Available");
}
}
【问题讨论】:
-
你在哪里打电话给
setStatus? -
显示您的
main方法。
标签: java methods boolean output setter