Tv has a Remocon. (Tv는 Remocon을 가지고 있다.)
자식클래스 has a 부모클래스
public class Tv extends Remocon {
}
public class Remocon {
private int ch; // 0 ~ MAX_CH
private int vol; // 0 ~ MAX_VOL
private final int MAX_CH = 99;
private final int MAX_VOL = 10;
public void upCh() {
ch++;
if(ch == MAX_CH) {
ch = 0;
return;
}
}
public void downCh() {
ch--;
if(ch < 0) {
ch = MAX_CH;
return;
}
}
public void upVol() {
vol++;
if(vol == MAX_VOL) {
return;
}
vol++;
}
public void downVol() {
vol--;
if(vol == 0) {
return;
}
vol--;
}
// Getter & Setter
public int getCh() {
return ch;
}
public void setCh(int ch) {
this.ch = ch;
}
public int getVol() {
return vol;
}
public void setVol(int vol) {
this.vol = vol;
}
}
public class MainWrapper {
public static void main(String[] args) {
// Tv 객체 선언 & 생성
Tv tv = new Tv();
// Tv 객체 메소드
tv.upCh();
tv.upVol();
System.out.println(tv.getCh());
System.out.println(tv.getVol());
tv.downCh();
tv.downVol();
System.out.println(tv.getCh());
System.out.println(tv.getVol());
}
}