previous | start | next

## Static Methods

- Don't operate on objects
- Example: `Math.sqrt`
- Example: factory method

      public static Greeter getRandomInstance()
      {
       if (generator.nextBoolean()) // note: generator is static field
       return new Greeter("Mars");
       else
       return new Greeter("Venus");
      }

- Invoke through class:

      Greeter g = Greeter.getRandomInstance();

- Static fields and methods should be rare in OO programs

previous | start | next