Class Declaration with a Method That Has One Parameter

We now declare class GradeBook (Fig. B.3) with a displayMessage method that displays the course name as part of the welcome message. (See the sample execution in Fig.B.4.) The new method requires a parameter that represents the course name to output.

 1   // Fig. B.3: 2   // Class declaration with one method that has a parameter. 3  4   public class GradeBook 5   { 6      // display a welcome message to the GradeBook user 7      public void displayMessage( String courseName8      { 9         System.out.printf( "Welcome to the grade book for\n%s!\n",10            courseName );                                          11      } // end method ...

Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.