메소드
- 메소드 == 함수
- 관련된 기능을 가진 모듈 (집합)
- 리턴값은 반드시 1개
메소드 정의(생성)
public static void main(String[] args) {
}
- public - modifier, 접근 제어자 ( ↔ private)
- static - 메모리 위치
- void - 리턴 타입
- main - 메소드명(식별자)
- (String[] args) - 파라미터
- main(String[] args) : 메소드 시그니쳐 (파라미터 타입, 개수) ⭐⭐
- 메소드 오버로딩 (overloading) : 메소드 시그니쳐가 다르면 같은 이름의 식별자 생성 가능
int sum(int a, int b) {};
void sum(int a, int b, int c) {};
void sum(double i, double j) {};
- { } - 블럭 바디
메소드 호출
int val = method(1, 2, 3);
- 리턴값이 없는 경우 : 식별자(값, …);
- 리턴값이 있는 경우 : 변수 = 식별자(값, …);