Abstract and interface Basics

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

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.