The void Keyword


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

ExampleVoid.java (the void keyword)
01// Java program using the void keyword
02public class ExampleVoid {
03  public static void main( String[ ] args ) {
04    int x = 10;
05    ExampleVoid myObj = new ExampleVoid( x );
06    myMethod( myObj.x );
07  }
08  // a member variable
09  double x = 5.0;
10  // a constructor
11  public ExampleVoid( int x ) { this.x = x; }
12  // a member method
13  public static void myMethod( double x ) { System.out.print( x ); }
14}
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.