반환(getter) 메소드
반환 메소드(getter method)
형태
String name;
public String getName(){
return this.name;
}int score;
public int getScore(){
return this.score;
}데모 1 : 일반적인 클래스
class Student{
String name;
int score;
void setName(String name){
this.name = name;
}
void setScore(int score){
this.score = score;
}
String getName(){
return this.name;
}
int getScore(){
return this.score;
}
}
public class GetterMethodExample01 {
public static void main(String[] args){
Student stu = new Student();
stu.setName("피카츄");
stu.setScore(80);
System.out.println("이름 : " + stu.getName());
System.out.println("점수 : " + stu.getScore());
}
}데모 2 : 계산을 수행하는 반환 메소드
Last updated