Sub-classes inherit parent class private ask everyone to explain & lt ;? Php & nbsp; class & nbsp; A {private & nbsp; function & nbsp; test ($ n) {echo & nbsp; "11 ";}} class & nb subclass inherit parent class private ask for details
Class {
Private function test ($ n ){
Echo "11 ";
}
}
Class B extends {
Function test (){
Echo "22 ";
}
}
Class C extends {
}
$ B1 = new B ();
$ B1-> test ();
?>In this code, the parent class has a private method. isn't the PHP rule that the subclass cannot inherit the private method of the parent class? but I have written a method of the same name in the subclass. if one of them has a parameter, an error is returned. if neither of them is correct, why ..... Share:
------ Solution --------------------
Private: inheritance can be inherited, but it cannot be run and added to display. since you have set text () to private in Class A, although the download is inherited in class C, but it cannot run. if you add A public method to call text () in Class. Then you can call it in class C to see if it is OK. The moderator was shocked.
------ Solution --------------------
The private method cannot be operated,
You need to understand the object-oriented concept. B inherits the concept of A. B is more specific to A, B is A, A has, B will have