1. Home
  2. Computing & Technology
  3. Java

Designing and Creating Objects

By Paul Leahy, About.com

7 of 7

Multiple Objects

Now we can begin to see the power of objects. I could extend the program:

public class BookTracker {

   public static void main(String[] args) {

     Book firstBook = new Book("Horton Hears A Who!","Dr. Seuss","Random House");
     Book secondBook = new Book("The Cat In The Hat","Dr. Seuss","Random House");
     Book anotherBook = new Book("The Maltese Falcon","Dashiell Hammett","Orion");
     firstBook.displayBookData();
     anotherBook.displayBookData();
     secondBook.displayBookData();
   }
}

From writing one class definition we now have the ability to create as many Book objects as we please!

Explore Java
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Java
  4. Java Syntax
  5. Working With Objects
  6. Multiple Objects

©2009 About.com, a part of The New York Times Company.

All rights reserved.