Inheritance problem and solution
小周
小周 2018-07-19 11:05:04
0
3
1074

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?

3433333.png


小周
小周

reply all(2)
Summer

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

无忌哥哥

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.

  • reply Um, okay, but the coverage of the method I asked about also means this, right? Prove that I understand correctly?
    小周 author 2018-07-19 11:17:09
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template