Create a folder called GBook and store the following two files in there.
// Fig. 3.1: GradeBook.java // Class declaration with one method. public class GradeBook { // display a welcome message to the GradeBook user public void displayMessage() { System.out.println( "Welcome to the Grade Book!" ); } // end method displayMessage } // end class GradeBook
// Fig. 3.2: GradeBookTest.java // Creating a GradeBook object and calling its displayMessage method. public class GradeBookTest { // main method begins program execution public static void main( String[] args ) { // create a GradeBook object and assign it to myGradeBook GradeBook myGradeBook = new GradeBook(); // call myGradeBook's displayMessage method myGradeBook.displayMessage(); } // end main } // end class GradeBookTest
You compile both files and run the one having main function. To compile the classes, type the command
javac GradeBook.java GradeBookTest.java
or
javac *.java