JAVA 복습하기

서화진·2022년 8월 17일
0

JAVA 학습일지

목록 보기
6/13

1) 접근제어 지시자(access modifier) 와 정보은닉(information hiding)



package ch10;

public class BirthDay {
	
	private int day;
	private int month;
	private int year;
	
	private boolean isValid;
	
	public int getDay() {
		return day;
	}
	
	public void setDay(int day) {
		this.day = day;
	}
	
	public int getMonth() {
		return month;
	}
	
	public void setMonth(int month) {
		this.month = month;
	}
	
	public int getYear() {
		return year;
	}
	
	public void setYear(int year) {
		this.year = year;
	}
	
	public void showDate() {
		if(isValid) {
			System.out.println( year + "년 " + month + "월 " + day + "일 입니다.");
			
		}else {
			System.out.println("유효하지 않는 날짜입니다.");
		}
	}
	
	
}


package ch10;

public class BirthDayTest {

	public static void main(String[] args) {

		BirthDay date = new BirthDay();
		
		date.setYear(2019);
		date.setMonth(12);
		date.setDay(30);
		
		date.showDate();
	}

}

출력값

2019년 12월 30일 입니다.


  • private : 외부 클래스, 상속 관계의 클래스에서 접근불가
  • get() / set() 메서드

처음 강의를 보고 있을땐 정말 1도 이해가 안됐었는데,
다시 한번 찬찬히 코딩을 쳐보니 아주 조~금은 이해가 되가고 있다. 아주 조금..^^
선생님이 말씀하시는 내용을 그때그때 깨닫게 되는 날이 빨리 오기를~

profile
초보 개발자 / 학습일지 : https://velog.io/@dinyyyyy

0개의 댓글