<?PHP//defining the Parent class classstu{ Public $name; protected $age; protected $grade; Private $address;//private variables are not inherited//when a subclass's method is exactly the same as the method of the parent class, called the override of the method Public function__construct () {Echo"Stu Constructor"; } Public functionShowinfo () {Echo $this->name. "| |".$this-Age ; } } ClassPupilextendsstu{//integrated parent class with extends keyword, class is single inheritance cannot be multiple inheritance Public functiontesing () {Echo"Pupils ' exams ..... "; } } ClassGraduateextendsstu{ Public functiontesing () {Echo"College exams ..... "; } } //call the members of the parent class//1. Class Name:: Method Name (); 2.parent:: Method Name (); $stu 1=Newpupil (); $stu 1->name= "Xiao Ming"; $stu 1-tesing (); $stu 1-Showinfo (); $stu 2=Newgraduate (); $stu 2->name= "Daming"; $stu 2-tesing (); $stu 2-showinfo ();?>
PHP Learning Note 25 "Inheritance of Classes"