批改状态:合格
老师批语:子类扩展了一个属性, 还行吧
作业1:命名空间
<?php
namespace one;
{
class A
{ }
(new \two\A())->show();
}
namespace two;
{class A
{
public function show()
{echo __METHOD__;}
}
}
//$a=new \two\A;
//$a->show();点击 "运行实例" 按钮查看在线实例

作业2
<?php
namespace _0731;
class A{
public $name;
public $age;
function __construct($name='李四',$age='50')
{ $this->name=$name;
$this->age=$age;
}
function getInfo()
{
return '姓名:'.$this->name.' 年龄:'.$this->age;
}
}
//$a=new A;
//echo $a->getInfo();
class B extends A
{
public $work;
public function __construct($work,$name = '李四', $age = '50')
{
parent::__construct($name, $age);
$this->work=$work;
}
public function get()
{
return $this->name.'工作是'. $this->work;
}
}
$b = new B('医生','张三',60);
echo $b->get();点击 "运行实例" 按钮查看在线实例

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号