면적은 100.0 이다.
사각형을 그리다
Sample Code
File : Shape
package kame.ch12.ex04;
public abstract class Shape {
public double res=0;
public abstract double area( );
public void printArea(){
System.out.println(" 면적은 "+res+" 이다. ");
}
}
File : Rectangle
package kame.ch12.ex04;
public class Rectangle extends Shape implements Drawable {
public int w = 10;
public int h = 10;
@Override
public double area() {
res = w*h;
return res;
}
@Override
public void draw() {
System.out.println("사각형을 그리다");
// TODO Auto-generated method stub
}
}
File : Ch12Ex05
package kame.ch12.ex04;
public class Ch12Ex05 {
public static void main(String[] args) {
Rectangle ref=null;
ref=new Rectangle();
ref.area(); // 추상 클래스인 Shape로 부터 상속 받음
ref.printArea(); // 추상 클래스인 Shape로 부터 상속 받음
ref.draw(); // 인터페이스인 Drawable로부터 상속 받음
}
}
Reference book 이클립스로 배우는 Java 6 Programming/ 임종권, 전병찬/ 가메출판사
댓글 없음:
댓글 쓰기