<? PHP // whether the abstract class or interface should be used; // If You Want To Inherit multiple method specifications, use the interface; // if you want to share the content of a method body, abstract classes are used./* abstract classes cannot inherit abstract class computer {Abstract Public Function _ run (); public function _ run2 () {echo 'I am a common method of the parent class 2 !! ';}} Class notecomputer extends computer {public function _ run () {echo' I am a subclass method! ';}}$ Notecomputer = new notecomputer (); $ notecomputer-> _ run (); $ notecomputer-> _ run2 (); * // * The interface member field must be a constant. The interface method must be an abstract method ~ In addition, you cannot write the abstract subclass inheritance interface, which is called implementation. You can implement multiple implementations */interface computer {const name = 'lenovo !!! '; Public function _ run (); public function _ run2 ();} interface computer2 {public function _ run3 ();} class notecomputer implements computer, computer2 {public function _ run () {echo 'I overwrote run! ';} Public function _ run2 () {echo' I overwrote run2! ';} Public function _ run3 () {echo' I overwrote run3! ';}}$ Notecomputer = new notecomputer (); $ notecomputer-> _ run (); $ notecomputer-> _ run2 (); $ notecomputer-> _ run3 (); echo notecomputer: Name; echo COMPUTER: Name;?>
Abstract and interface Basics