I am learning java. I wrote the following code but I am getting this error \"cant make a static reference to a non static input field\" in Arrayfunction(), when I try to take in
input
in your class is an instance variable (since it's not defined as static
), which means that each instance of MultidimArrays
has one of it's own. static
fields or methods (often referred to as "class variables/methods" are shared between all instances of a class.
Since Arrayfunction
is static
, it cannot refer to instance members of its class - there is no way for it to know which MultidimArray
to use. You can either solve this by making input
itself static, or by removing the static
qualifier from ArrayFunction
and create an instance of your class:
public static void main(String args[])
{
int array[][] arr = new int[2][3]; //typo here, variable needs a name :)
System.out.println("Passing array to a function");
MultidimArray ma = new MultidimArray();
ma.Arrayfunction(arr);
}