0

Receiving a non-static method cannot be referenced from static context. In this example I deleted all of the extra "stuff." All of the other examples I found had a lot of distractors that confused me. This is for studying for a final and is NOT part of an assignment.

I do not understand why there is an issue here - troubles understanding static/non-static issue altogether.

In this case all I expect is for 5207 to be the output.

package testcase;

public class Testcase {

int number = 5207;
public static void main(String[] args) {
    //int number = 5207;
    int div;
    div = divisor(number);
    System.out.println(div);
}

private int divisor(int num){

    return number;
}
theninja
  • 7
  • 2

1 Answers1

0

Try to become a static method like this:

  private static  int divisor(int num){
   return number;
   }

Or instance the object of class Testcase :

 Testcase tsc = new Testcase();
 div = tsc.divisor(number);
Abdelhak
  • 8,299
  • 4
  • 22
  • 36