<!-- 声明一个员工类,经理类继承自员工类 -->
<?
class employee{
protected $sal=3000;
public function getSal(){
$this->sal = $this->sal + 1200;
return $this->sal ;
}
}
class Manager extends employee {
//如果想让经理在员工工资的基础上多发1500元.
//必须先调用父类的getSal()方法.
public function getSal(){
parent::getSal();// 这里调用了父类的方法.
$this->sal = $this->sal + 1500;
return $this->sal ;
}
}
$emp = new employee();
echo "普通员工的工资是 " . $emp->getSal();
echo "<br>";
//xiariboke.com
$manager = new Manager();
echo "经理的工资是: " . $manager->getSal();
?>
<?php
class employee{
private $sal=3000;
//protected $sal=3000;
public function getSal(){
return $this->sal;
}
}
class Manager extends employee {
protected $sal=5000;
public function getParentSal(){
//这里返回的是父类的private属性.
return parent::getSal();
}
}
$manager = new Manager();
echo "PHP ".phpversion()."<br>";
echo $manager->getSal();
echo "<br>";
echo "parent's \$sal ".$manager->getParentSal();
//xiariboke.com
?>
<?php
class employee{
//private $sal=3000;
protected $sal=3000;
public function getSal(){
return $this->sal;
}
}
class Manager extends employee {
protected $sal=5000;
//xiariboke.com
public function getParentSal(){
//这里返回的是父类的private属性.
return parent::getSal();
}
}
$manager = new Manager();
echo "PHP ".phpversion()."<br>";
echo $manager->getSal();
echo "<br>";
echo "parent's \$sal ".$manager->getParentSal();
?>
<?php
class employee{
private $sal=3000;
public function getSal(){
return $this->sal;
}
}
class Manager extends employee {
private $sal=5000;
//重写过的方法
public function getSal(){
return $this->sal;
}
public function getParentSal(){
//这里返回的是父类的private属性.
return parent::getSal();
}
}
$manager = new Manager();
echo "PHP ".phpversion()."<br>";
echo $manager->getSal();
echo "<br>";
echo "parent's \$sal ".$manager->getParentSal();
?>
<?php
class employee{
private $sal=3000;
public function getSal(){
return $this->sal;
}
}
class Manager extends employee {
protected $sal=5000;
public function getParentSal(){
return $this->sal;
}
}
$manager = new Manager();
echo "PHP ".phpversion()."<br>";
echo $manager->getSal();
?>
<?php
class employee{
protected $sal=3000;
public function getSal(){
return $this->sal;
}
}
class Manager extends employee {
protected $sal=5000;
public function getParentSal(){
return $this->sal;
}
}
$manager = new Manager();
echo "PHP ".phpversion()."<br>";
echo $manager->getSal();
?>
<?php
class employee{
private $sal=3000;
public function getSal(){
return parent::$this->sal;
}
}
class Manager extends employee {
protected $sal=5000;
public function getSal(){
return parent::$this->getSal();
}
}
$manager = new Manager();
echo "PHP ".phpversion()."<br>";
echo $manager->getSal();
?>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有