Sub-classes inherit parent class private ask for details

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.