본문 바로가기
자바/자바

[자바] TV클래스를 상속받는 ColorTv, ColorTV를 상속받는 IPTV클래스를 작성하시오

by 이얏호이야호 2020. 4. 28.

공부하시는대에 도움이 됐으면 좋겠습니다.

답안코드 확인해주세요!

 

더보기
class TV { // Tv클래스입니다.

   private int size;



   public TV(int size) {

      this.size = size;

   }



   protected int getSize() {

      return size;

   }

}



class ColorTV extends TV { // TV클래스를 상속받은 ColorTV입니다.

   private int colors;



   public ColorTV(int colors, int size) {

      super(size); // size입력

      this.colors = colors; // colors입력

   }



   public void printProperty() { // ColorTv의 Size와 Color를 출력합니다.

      System.out.print(getSize() + "인치 " + colors + "컬러");

   }

}



class IPTV extends ColorTV {

   String IP;



   public IPTV(String IP, int size, int colors) { // IPTV의 IP, Size,Color를 출력합니다.

      super(colors, size);

      this.IP = IP;

   }



   public void printProperty() { // 출력입니다.

      System.out.print("나의 IPTV는" + IP + "주소의");

      super.printProperty();

   }

}



public class makeTV {



   public static void main(String[] args) {

      IPTV iptv = new IPTV("192.1.1.2", 32, 2048); // "192.1.1.2" 주소에 32인치, 2048컬러

      iptv.printProperty();



   }



}

댓글