Blogger Information
Blog 25
fans 0
comment 0
visits 15881
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0731命名空间及类
杨发国的博客
Original
641 people have browsed it

作业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();

运行实例 »

点击 "运行实例" 按钮查看在线实例

1.png

 

作业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();

运行实例 »

点击 "运行实例" 按钮查看在线实例

2.png

Correction status:qualified

Teacher's comments:子类扩展了一个属性, 还行吧
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post