[클래스] __construct 조상클래스의 생성자
// 조상 클래스의 생성자
class Point {
var $x, $y;
function __construct($x, $y) {
$this->x = $x;
$this->y = $y;
}
}
class Point3D extends Point {
var $z;
function __construct($x, $y, $z) {
parent::__construct($x, $y);
$this->z = $z;
}
public function getLocation() {
return 'x :' . $this->x . ', y :' . $this->y . ', z :' . $this->z;
}
}
$p3 = new Point3D(100,200,300);
echo $p3->getLocation();
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기