자바 초보부터 B형까지7 -변수의 범위, 지역변수, 전역변수 설정방법-
1. 자바에서 전역변수 선언 class내에서 맨 위에 public static이라고 선언한 변수는 global 변수가 된다. 그래서 해당 class내의 모든 함수,class내에서 해당 global 변수를 참조할 수 있게 된다 public class Main { //arr은 모든 함수에서 참조할 수 있게 된다 public static int[] arr = new int[]{1, 2, 3, 4}; public static int sumAll() { int sum = 0; for(int i = 0; i < 4; i++) sum += arr[i]; return sum; } public static void main(String[] args) { int totalSum = sumAll(); System.out.p..