少了两个“}”号而已,应该是这样吧。 class Book { boolean checkout=false; Book(boolean checkout){ checkout=checkout; } void checkin(){ checkout=false; } public void finalize(){ if (checkout){ System.out.println("error:checked out"); } } } public class Deathcondition { public static void main(String args[]){ Book novel =new Book(true); novel.checkin(); new Book(true); System.gc(); } }
class Book {
boolean checkout=false;
Book(boolean checkout){
checkout=checkout;
}
void checkin(){
checkout=false;
}
public void finalize(){
if (checkout){
System.out.println("error:checked out");
}
}
}
public class Deathcondition {
public static void main(String args[]){
Book novel =new Book(true);
novel.checkin();
new Book(true);
System.gc();
}
}