2012년 12월 29일 토요일

[Ch10Ex05] Method Overwriting

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;

}

File : Point3D
package kame.ch10.ex05;

public class Point3D extends Point2D {

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

System.out.println(" x grid : " + x);
System.out.println(" y grid : " + y);
System.out.println(" z grid : " + z);
}
}

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/ 임종권, 전병찬/ 가메출판사

댓글 없음:

댓글 쓰기