class TV {
private int size;
public TV(int size) {this.size = size;}
protected int getSize() {return size;}
}
public class ColorTV extends TV {
private int color;
protected int getColor() {return color;}
public ColorTV(int size,int color) {
super(size);
this.color = color;
}
void printProperty() {
System.out.println(getSize()+"인치 "+color+"컬러");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ColorTV myTV = new ColorTV(32,1024);
myTV.printProperty();
}
}
public class IPTV extends ColorTV {
private String ip;
public IPTV(String ip, int size, int color) {
// TODO Auto-generated constructor stub
super(size,color);
this.ip = ip;
}
void printProperty() {
System.out.println("나의 IPTV는 "+ip+"주소의 "+getSize()+"인치 "+getColor()+"컬러");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
IPTV iptv = new IPTV("192.1.1.2",32,2048);
iptv.printProperty();
}
}
결과
나의 IPTV는 192.1.1.2주소의 32인치 2048컬러
'명품JAVA프로그래밍 > 5장 상속' 카테고리의 다른 글
[명품JAVA프로그래밍] 5장 실습문제 5번 (0) | 2022.01.12 |
---|---|
[명품JAVA프로그래밍] 5장 실습문제 4번 (0) | 2022.01.12 |
[명품JAVA프로그래밍] 5장 실습문제 3번 (0) | 2022.01.12 |
[명품JAVA프로그래밍] 5장 실습문제 1번 (0) | 2022.01.12 |
[명품JAVA프로그래밍] 5장 Open Challenge (0) | 2022.01.12 |