Return to Unit Menu | Java Main Page | MathBits.com | Terms of Use  

 Methods -- Style 1 

Style 1:  Our first style of method will simply perform an independent task.  It will not receive any parameters and it will not return any values.  Such a method definition starts with the reserved words public static void, followed by the name of the method and a set of parentheses.  The word public indicates that there are no restrictions on the use of the method.  The word static means that all of the method's data will come from parameters or internal computations, with no reference to variables.  The word void is used to indicate that no value is returned.

//Demo Program for Methods

import java.io.*;
import BreezyGUI.*;

public class DisplayClass
      public static void main (String[ ] args)
          System.out.println("Calling all methods!");
          asterisks( );     //invoking method (calling the method)
     System.out.println("Great job, method!");
          asterisks( );    //
invoking method again
          System.out.println("We're outta here!");

    //Method for astericks
     public static void asterisks( )   // Method definition
          int count; 
          for(count = 1; count<=20; count++)

          System.out.println( );


Calling all methods!
Great job, method!
We're outta here!

Return to Unit Menu | Java Main Page | MathBits.com | Terms of Use