static methods in java code example

Example 1: how to call a static method in java

class scratch{
	public static hey(){
		System.out.println("Hey");
    }
	public static void main(String[] args){
		hey();
        //print Hey to the console
    }

Example 2: Static method in java

We can declare a method as static by adding keyword “static” before method name.
Let’s see example on static method in java.

public class StaticMethodExample
{
   static void print()
   {
      System.out.println("in static method.");
   }
   public static void main(String[] args)
   {
      StaticMethodExample.print();
   }
}