[클래스] Overriding 오버라이딩
/*
오버라이딩(overriding)이란, ‘조상 클래스로부터 상속받은 메서드를 자손 클래
스에 맞게 재정의 하는 것’을 말한다.
조상 클래스로부터 상속받은 메서드를 자손 클래스에서 그대로 사용할 수 없는 경우가
많기 때문에 오버라이딩이 필요하다.
*/
class Point {
var $x=10, $y=20;
public function getLocation() {
return 'x :' . $this->x . ', y:' . $this->y;
}
}
class Point3D extends Point {
var $z=30;
public function getLocation() {
return parent::getLocation() . ', z :' . $this->z;
}
}
$p = new Point();
echo $p->getLocation().'<br />';
$p3 = new Point3D();
echo $p3->getLocation();
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기