[경북대학교]자바프로그래밍 6장 과제 소스코드
- 최초 등록일
- 2021.07.31
- 최종 저작일
- 2021.04
- 5페이지/ MS 워드
- 가격 1,000원
소개글
"[경북대학교]자바프로그래밍 6장 과제 소스코드"에 대한 내용입니다.
목차
1. Abstract 실습: 아래 코드를 참조하여 MyPoint.java와 MyColorPoint.java를 완성하라
2. InstanceOf와 DownCasting 연습: Report #03에서 구현한 Music, Classic, Pop 클래스를 이용하여 MusicInstance.java 메인 프로그램을 작성하시오.
본문내용
(결과는: 4, 3, blue).
abstract class MyPoint {
private int x;
private int y;
public MyPoint(int x, int y) { .... }
protected abstract void move(int x, int y); //새로운 x, y 위치로 이동
protected abstract void reverse(); //(x, y)에서 (y, x)로 위치 변경
protected void show() { .... } }
public class MyColorPoint extends MyPoint { public MyColorPoint( .... ) { .... } protected void move (... ) { .... } protected void reverse() { ... }
public void show() { ... }
public static void main(String[] args) {
MyPoint p = new MyColorPoint(2, 3, "blue");
p.move(3, 4);
p.reverse();
p.show(); // 이 메소드의 실행 결과 "4, 3, blue"가 출력된다.
} }
public class MyColorPoint extends MyPoint{
int x;
int y;
private String color;
public MyColorPoint(int x, int y, String z){
this.x=x;
this.y=y;
this.color=z;
}
protected void move(int x, int y) {
this.x=x;
this.y=y;
}
protected void reverse() {
int temp;
temp=this.x;
this.x=this.y;
this.y=temp;
참고 자료
없음