생성자
클래스 안에서 빵을 만들 때, 이름을 새기는 것.
public Course(){
}
public Course(String title, String tutor, int days) {
this.title = title;
this.tutor = tutor;
this.days = days;
}
public, private
📝 자바의 클래스는, 밖에 드러나도 되는 것들을 public, 함부로 바꾸면 안되는 것들을 private으로 구분해서 나타낸다.
📝 대부분의 클래스가 멤버변수를 private으로 설정한다.(쉽게 바꾸지 못하도록)
: 변수 내용 설정(바꾸기)
public void setTitle(String title){
this.title = title;
}
// private로 선언된 멤버변수를 바꿀 수 있는 방법
// Lombok Setter 쓰면 없어도 되는 코드
// 사용방법
course.setTitle(title);
: Private 멤버변수 조회(가져오는거)
public String getTitle(){
return this.title;
}
Tutor tutor = new Tutor(name, bio);
💡 이걸 쓰려면 클래스에 생성자를 추가해줘야함!! 원래 기본생성자는 파라미터 없는거니까.(5분정도 고민함)
this.name = name;
💡 이 과정이 없으면 실행했을때 null로 뜸.