클래스의 필드들이 public이라 외부에서 마음대로 변경할 수 있다.
웬만하면 클래스의 필드는 private 접근 제한자를 써서 클래스 내부에서의 접근을 제한한다.
Getter : 객체의 필드 값을 읽어올 때 사용
Setter : 객체의 필드 값을 변경할 때 사용
package com.ll.domain;
public class Quotation {
private int id;
private String content;
private String author;
public Quotation(int id, String content, String author) {
this.id = id;
this.content = content;
this.author = author;
}
public int getId() {
return id;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
}