The void Keyword


The void keyword allows us to create methods which do not return a value.

ExampleVoid.java (the void keyword)
// Java program using the void keyword
public class ExampleVoid {
  public static void main( String[ ] args ) {
    int x = 10;
    ExampleVoid myObj = new ExampleVoid( x );
    myMethod( myObj.x );
  }
  // a member variable
  double x = 5.0;
  // a constructor
  public ExampleVoid( int x ) { this.x = x; }
  // a member method
  public static void myMethod( double x ) { System.out.print( x ); }
}
Output:           Result:

Review: Access Modifier
    Which access modifier of a method allows it to be accessible within the class in which it is defined and in its subclass(es)?

      Default (declared/defined without using any modifier)
      private
      protected
      public
        Result:




      I’m not a big fan of stairs. They are always up to something.