[ 오버라이딩(Overriding) *** ]
class Shape{
protected int x; //x좌표
protected int y; //y좌표
public Shape(int x,int y) {
this.x=x;
this.y=y;
}
public void draw() {
System.out.println("도형그릴 좌표:x=" + x +",y=" + y);
}
}
class Rect extends Shape{
public Rect(int x,int y) {
super(x,y);
}
public void draw() { //오버라이딩
System.out.println(x +"," + y + "의 위치에 사각형 그리기");
}
public void draw(String color) { //오버로딩
System.out.println(color +"색상의 사각형 그리기");
}
}
public class Test01_오버라이딩 {
public static void main(String[] args) {
Rect r=new Rect(100,200);
r.draw();
r.draw("빨강");
}
}