import java.util.Random;
public class Book {
    String title;
    int id = 0;
    public Book(String book){
        String title = book;
        int id = id + 1;
    }
    public String toString(){
        return(title+id);
    }
    public static void main(String[] args) {
        Book book1 = new Book("d");
    }
}
Book.main(null);
|           int id = id + 1;
variable id might not have been initialized
import java.util.Random;
public class Book {
    public String title;
    public static int count;
    private final Date creationDate;
    public Book(String title){
        this.title = title;
        this.creationDate = new Date();
    }
    public int makeId(){
        Random random = new Random();
        int id = random.nextInt(1000);
        count++;
        return id;
    }
    public int getCount(){
        return count;
    }
    public String toString(){
        return this.title;
    }

    public long shelfLife() {
        Date currentDate= new Date();
        long timeDiff = Math.abs(this.creationDate.getTime()- currentDate.getTime());
        return timeDiff;
    }

    public static void main(String[] args){
        try {
            Book book1 = new Book("book1");
            Book book2 = new Book("book2");
            Thread.sleep(1000);
            System.out.println("Book: " + book1.toString() + ", id: " + book1.makeId());
            System.out.println("Book: " + book2.toString() + ", id: " + book2.makeId());
            System.out.println("bookcount: " + count);
            
            System.out.println(book1.shelfLife());
            System.out.println(book2.shelfLife());
        }
        catch (Exception e) {
            System.out.println("error");
        }

    }
}
Book.main(null);
Book: book1, id: 760
Book: book2, id: 972
bookcount: 2
1008
1009
public class Novel extends Book{
    public String author; 
    public Novel(String title){
        super(title);
    }
    public void author(String author){
        this.author = author;
    }
    public String getAuthor(){
        return author;
    }
    public static void main(String[] args){
        Novel novel1 = new Novel("novel1");
        Novel novel2 = new Novel("novel2");
        System.out.println(novel1.toString());
        System.out.println(novel1.shelfLife());
        System.out.println(novel2.toString());
        System.out.println(novel2.shelfLife());
    }
}
Novel.main(null);
novel1
1
novel2
2
public class Textbook extends Book{
    public String publisher;
    public Textbook(String title){
        super(title);
    }
    public void publisher(String publisher){
        this.publisher = publisher;
    }
    public String getPublisher(){
        return publisher;
    }
    public static void main(String[] args){
        Textbook textbook1 = new Textbook("textbook1");
        Textbook textbook2 = new Textbook("textbook2");
        System.out.println(textbook1.toString());
        System.out.println(textbook1.shelfLife());
        System.out.println(textbook2.toString());
        System.out.println(textbook2.shelfLife());
    }
}
Textbook.main(null);
textbook1
22
textbook2
23