Home > Backend Development > PHP Tutorial > 关于继承的1点疑惑,希望大家可以帮帮忙

关于继承的1点疑惑,希望大家可以帮帮忙

WBOY
Release: 2016-06-13 12:31:27
Original
751 people have browsed it

关于继承的一点疑惑,希望大家可以帮帮忙!
class f {
    private $str = "123";
    public function fun() {
         echo $this->str;
    }
}

class s extends f {
    public $str = "abc";
}

$s = new s();
$s->fun();
输出:123


class f {
    public $str = "123";
    public function fun() {
         echo $this->str;
    }
}

class s extends f {
    public $str = "abc";
}

$s = new s();
$s->fun();
输出:abc

第一个的输出很疑惑,为什么会输出父类的属性值?麻烦大家给我分析分析内存,有图说明更好,谢谢大家了。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template