ProAnswers.org

How to declare Class with a method that has a parameter?

public class MainClass

{

   public static void main( String args[] )

   { 

      GradeBook myGradeBook = new GradeBook(); 

 

      String courseName = "Java ";

      myGradeBook.displayMessage( courseName );

   }

 

}

 

class GradeBook

{

   public void displayMessage( String courseName )

   {

      System.out.printf( "Welcome to the grade book for

%s!
",

         courseName );

   }

 

}

 

output

Welcome to the grade book for

Java !