2012년 12월 29일 토요일

[Ch10Ex05] Reference variable Super

Result :

 x grid : 10
 y grid : 20
 z grid : 30


Sample Code 

File : Point2D
package kame.ch10.ex05;

public class Point2D {

protected int x =10;
protected int y=20;

public void showPoint(){
System.out.println(" x grid : " + x);
System.out.println(" y grid : " + y);
}
}


File : Point3D
package kame.ch10.ex05;

public class Point3D extends Point2D {

protected int z = 30;
public void showPoint(){

super.showPoint();
System.out.println(" z grid : " + z);
}
}

// showPoint() 메소드를 오버라이딩 한 메소드를 보면 Point2D 클래스의 내용이 중복되어 기술되어 있음.

File :Ch10Ex05

import kame.ch10.ex05.Point3D;

public class Ch10Ex05 {

public static void main(String[] args) {
Point3D pt = new Point3D();
pt.showPoint();
}
}

Reference book : 이클립스로 배우는 Java 6 Programming/ 임종권, 전병찬/ 가메출판사

댓글 없음:

댓글 쓰기