Referencing a variable in the main function - Java <p>I have written a simple summation function where I add up values of an array. I need to reference the values of the array (which is within the main class) in my function. My code looks like this:</p> <pre><code>public class myClass { public static void main(String[] args) throws Exception { int[] myArray = {0,1,2,3,4}; //Some random operations } public static int sum(int low,int up) { int sum; for (int k=low; k&lt;=up; k++) { sum +=myArray[k]; } return sum; } } </code></pre> <p>However I get the error "myArray cannot be resolved to a type". Why is this error occurring? How may I fix it? Thanks in advance.</p>