package com.thinkinjava.objects.initialization;

class Book {
    boolean checkedOut = false;
    Book(boolean checkOut) {
        checkedOut = checkOut;
    }

    void checkIn() {
        checkedOut = false;
    }
    protected void finalize() {
        System.out.println("finalize");
        if (checkedOut)
            System.out.println("Error: checked out");
    }
}

public class terminationCondition {
    public static void main(String[] args) {
        Book novel = new Book(true);
        novel.checkIn();

        // drop the reference, forget to clean up
        new Book(true);

        // force garbage collection & finalization
        System.out.println("gc");
        System.gc();

        System.out.println("another gc");
        System.gc();
    }
}
