cp. printinfo(); 동적바인딩 >> 다형성이 실현됨
class Point {
int x;
Point() {
this.x=10;
}
void printInfo() {
System.out.println("점 ("+this.x+")");
}
}
class ColorPoint extends Point {
String color;
ColorPoint(String color) {
// super();
this.color=color;
}
void printInfo() {
System.out.println(this.color+"점 ("+this.x+")");
}
}
public class Test02 {
public static void main(String[] args) {
ColorPoint cp=new ColorPoint("분홍");
cp.printInfo();
}
}
'JAVA > 코드' 카테고리의 다른 글
캡슐화와 오버라이딩 활용 예제 (0) | 2025.02.23 |
---|---|
자바 -클래스 (0) | 2025.02.17 |
15일차 과제 - UPDOWN게임 (0) | 2025.02.06 |
JAVA의 메소드 유형 (0) | 2025.02.02 |
정렬 - 선택, 버블, 삽입 (0) | 2025.01.30 |