Name $ name; $ this-& gt; age $ age;} publicfunctionshow () {echo $ this-& gt; name. & quot; | & quot ;. $ this-& gt; age ;}} classChildextendsPerson {}$ childnewChild (& quot; aaa & quot;, 5); $ child-& gt; show ();? & Gt; Why is aaa printed? | 5 subclass does not inherit the show () method of the parent class, and then the parent class object is inherited by php.
Class Person {
Private $ name;
Private $ age;
Public function _ construct ($ name, $ age) {$ this-> name = $ name; $ this-> age = $ age;} public function show () {echo $ this-> name. "| ". $ this-> age ;}} class Child extends Person {}$ child = new Child ("aaa", 5); $ child-> show ();
?>
Why is aaa printed? | 5
Shouldn't the subclass inherit the show () method of the parent class, and then $ this in the parent class method should not refer to the object instance of the subclass?
However, when the subclass is inherited, it should not inherit the private member attribute of the parent class.
So why can I print something ???