<? PHP // study what can be inherited when a class inherits from another class. Class A {// public attribute public $ name = "" of the parent class; // The protected attribute protected $ age = "20" of the parent class "; // Private Property of the parent class private $ sex; // public method of the parent class public function testing1 () {echo "test1 ()";} // protected method of the parent class protected function testing2 () {echo "Test2 ()";} // Private method of the parent class private function testging3 () {echo "test3 ()" ;}} Class B extends a {public function getage () {return $ this-> age;} public function gotest2 () {$ this-> testing2 () ;}$ b1 = new B (); // 1. it proves that the variable modified by public can inherit echo $ B1-> name; // 2. it proves that the variable modified by protected can also inherit echo $ B1-> getage (); // 3. private variables cannot be inherited by the quilt class. // 4. The public function can be inherited from $ B1-> testing1 (); // 5. The protected method can be inherited. $ B1-> gotest2 (); // 6. Private methods cannot be inherited.?>
Key points:
In PHP, inheritance is a single inheritance, that is, one class can only inherit another class,
If you want a class to inherit multiple classes, you can use multiple inheritance methods, that is, Grandpa's variable father inherits, and Dad's variable son inherits,
Therefore, the son inherits the attributes of both Grandpa and dad.