PHP access control problem

abstract class base { 
    public function inherited() { 
        $this->overridden(); 
    } 
    private function overridden() { 
        echo "base"; 
    } 
} 

class child extends base { 
    private function overridden() { 
        echo "child"; 
    }
}
$test = new child();
$test->inherited();

Why does it output base, here? my cognition is to output child.

Php
May.22,2021

if you want to display child, you also need to override the inherited method. If not, the inherited of the original parent class also calls the overridden method of the original parent class. So the result is base


although the subclass inherits the parent class, it does not override the inherited method and actually calls the method of the parent class

when the PS: subclass inherits the parent class, the properties and methods of the two are separated. This does not mean that the overridden method is inherited or the mathematics overrides it in memory

.

since the method of the parent class is called, $this is naturally the parent class itself, so what is output is that there are some inheritance and polymorphic knowledge in base

PS: is not understood enough, and it is not very clear. I hope there is a great god to point out the exact difference

.

Private methods cannot be overridden
otherwise what is the meaning of the word private

Menu