This example first does not instantiate the parent class, and then when the subclass does not override the method of the parent class, $cat1->cry() calls the parent class. What does it mean? The subclass method is also written as echo 'animal call.. ';? What I understand is that if this is the case, doesn’t saying it mean that you haven’t said it?
Summer2018-07-19 11:45:51
Your cat class inherits the animal class. If there is no cry method in the cat class, your $cat1->cry() calls the cry method of the parent class and outputs the animal cry. . When your cat class has a cry method, it is called the parent class override. Then $cat1->cry() gives priority to calling the cry method of the subclass and outputs abc
无忌哥哥2018-07-19 11:12:39
The subclass does not override the parent class, that is, the subclass just inherits the parent class without making changes. For example, the parent class $i=1; the subclass does not define $i, then the parent class is called in the subclass. $i is still 1. If the subclass covers the parent class, for example, $i=2 is defined in the subclass; then $i is equal to 2 in the end.