본문 바로가기
프로그램/Java 1000제

Java 19제] 1~10까지 출력하시오.(추상클래스의 추상메서드 사용)

by 건티 2022. 12. 6.
728x90

출처 : 반크_세계유산 경복궁

 

참고풀이]

상속할 파일)

public abstract class OneAndTenPaPa {
   int N;//멤버번수
   int S;
   int E;

   public OneAndTenPaPa()
   {
      S=1;
      E=10;
   }

   //멤버 메서드
   public void Show(int N)
   {
      this.N=N;
      for(int i=1; i<=this.N; i++)
         System.out.printf("%3d",i);
      System.out.println();
   }

 

   public abstract void Show(int Start, int End);

   public static void main(String[] args) {
      // TODO Auto-generated method stub
   }
}

상속받을 파일)

public class OneAndTenKid4 extends OneAndTenPaPa {

   //추상메서드를 OverRiding함.
   public void Show(int Start, int End)
   {
      for(int i=Start; i<=End; i++)
         System.out.printf("%3d",i);
      System.out.println();
   }

   public static void main(String[] args) {
      // TODO Auto-generated method stub
      OneAndTenKid4 oatk=new OneAndTenKid4();

      oatk.Show(1, 10);

   }

}

 

 

참고풀이 결과]

 

 

 

 

 

대한민국의 아름다운 영토, 독도의 가을

 

반응형

댓글