A static method is a class method, rather than an object method. So static methods cannot access not static methods without instantiating their objects.

public class Test {
   private double income = 5000;
   private double expenses = 7000;

   public static void main (String[] args) {   
      calculateBalance();
   }

   private void calculateBalance() {
      System.out.println(this.income - this.expenses);
   }
}

This code would generate the following error message.

Cannot make a static reference to the nonstatic method calculateBalance()

Since main() is static, it cannot call the nonstatic method calculateBalance(). Another mistake new Java programmer make is that they try to use “this” keyword.

public class Test{
   private double income = 5000;
   private double expenses = 7000;

   public static void main(String[] args) {   
      this.calculateBalance();
   }
   private void calculateBalance() {
      System.out.println(this.income - this.expenses);
   }
}

The program generates the following error.

public class Test{
   private double income;
   private double expenses;
   
   public static void main(String[] args) {
      Test t = new Test();
      t.calculateBalance();
   }

   Test() {
      this.income = 5000;
      this.expenses = 7000;
   }

   private void calculateBalance() {
      System.out.println(this.income - this.expenses);
   }
}

This program compiles and produces the output -2000. To access a nonstatic method from a static method, you need to instantiate its object first. “this” keyword cannot be used in static context. “this” is an object’s internal reference. Since a static method is a class method, it does not have an internal object reference.