getter, setter
package section2.hiding;
public class Student {
int studentID;
private String studentName;
int grade;
String address;
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
}
public class StudentTest {
public static void main(String[] args) {
Student student = new Student();
student.setStudentName("이이");
System.out.println(student.getStudentName());
}
}
get()
: private 변수에 접근해 값을 가져오는 public 메서드
set()
: private 변수에 접근해 값을 지정하는 public 메서드