1. 함수(function)

1) 개념

2) 구성요소

public class Practice {
		public static int add(int x, int y) { // 머리 : 이름, 매개변수 선언
					int result = int x + int y;  // 몸체 : 동작 과정 
					
					return result;  // 몸체 : 반환값
		}
}

3) 함수 호출

위에 생성한 add 함수 호출하기.

메인함수에서 매개변수가 2개이고 add함수에 3, 5라는 값을 넣어 함수를 호출하고 호출된 값을 result 변수에 저장하여 출력한다.

public class Practice {
		public static int add(int x, int y) { // 머리 : 이름, 매개변수 선언
					int result = int x + int y;  // 몸체 : 동작 과정 
					
					return result;  // 몸체 : 반환값
		}
		
		public static void main(String[] args) {
					int a = 3;
					int b = 5;
					add(a, b);
					
		System.out.println(add(a, b));

					// 또는 int result = add(3, 5)
					// System.out.println(result);
		}
}

2. 메서드(Method)

1) 개념

객체의 기능을 구현하기 위해 클래스 내부에 구현되는 함수

2) 메서드 선언

public static 리턴 타입(자료형 or void) 메서드명() {
			실행할 코드 작성;
			return;  // 리턴 타입이 void일 경우 return 없음. 
}