Academic Java    Java Tutorial  >  Quizzes  >  Object Orientation  >  class types

class types

public class Booker {

   private int numBooks;

   public Booker () {
      Book b0 = new Book("V Woolf","Orlando");
      Book b1 = new Book("S Richardson","Pamela");
      System.out.println(b0);
      System.out.println(b1);
      System.out.println("Number of books is "+numBooks);
   }

   public static void main(String[] args) {
      new Booker();
   }
//============================================
   class Book {
      String title,author;
      public Book(String a, String t) {
         author=a;
         title=t;
         numBooks++;
      }
      public String toString() {return "'"+title+"' by "+author;}
   }
}