void
void는 메서드 선언시 쓰이는 단어로 리턴되는 타입이 없음을 의미!
public static void main(String[] args) {
}
return : 결과값을 돌려주는 명령어
리턴되는 타입이 있을 때는?
메서드 선언시 리턴하려는 데이터의 타입을 써주고
바디에서 반드시 해당하는 타입에 맞는 값을 반환해야 함
//getters and setters
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
public static PersonBuilder builder() {
return new PersonBuilder();
}
int sum(int a, int b) {
return a+b;
}
'JAVA' 카테고리의 다른 글
String, int Test (선언, 입력, 비교) (1) | 2022.10.07 |
---|---|
시험 점수를 입력받아 총점, 평균 구하기 (0) | 2022.10.07 |
자바 반복문을 이용한 구구단 출력(while, do while, for) (0) | 2022.10.05 |
자바 반복문 while, do while, for 기본 문법 (0) | 2022.09.30 |
IF, Switch 조건문 가위바위보 (1) | 2022.09.30 |
자바 조건문 If, Else, Else if, Switch 기본 문법, 간단한 예제 (0) | 2022.09.29 |
LogicalTest (0) | 2022.09.29 |
LiteralsTest (0) | 2022.09.29 |
댓글