You cannot reference non-static elements from a static method.
Non-static elements (e.g. your fxn (int y)) can only be called from an instance of your class.
Example:
You can do it:
public class A { public int fxn(int y) { y = 5; return y; } } class Two { public static void main(String[] args) { int x = 0; A a = new A(); System.out.println("x = " + x); x = a.fxn(x); System.out.println("x = " + x); }
or you can declare your method static.
source share