Program 6.2: Create and Print a Website

Program 6.2 creates a new website, sets its fields, and prints the result.

class OOPTest {

  public static void main(String args[]) {
    website w = new website(); = "Cafe Au Lait";
    w.url = "";
    w.description = "Really cool!";
    System.out.println( + " at " + w.url + 
      " is " + w.description);
Program 6.2 requires not just the OOPTest class but also the website class. To make them work together put Program 6.1 in a file called Put Program 6.2 in a file called Put both these files in the same directory. Then compile both files in the usual way. Finally run OOPTest. Note that website does not have a main method so you cannot run it. It can exist only when called by other programs that do have main methods. Here's the output.

% javac
% javac
% java OOPTest
Cafe Au Lait at is Really cool!
Many of the applications you write from now on will use multiple classes. It is customary in Java to put every class in its own file. In Chapter 21 you'll learn how to use packages to organize your commonly used classes in different directories. For now keep all your .java source code and .class byte code files in one directory.

Copyright 1996, 1998 Elliotte Rusty Harold
This Chapter