Small examples of Polymorphism

Source: Internet
Author: User
<? PHP interface computer {public function version (); Public Function work ();} class notecomputer implements computer {public function version () {echo 'notebook ';} public function work () {echo 'can run win7 in a portable manner !! ';}} Class extends topcomputer implements computer {public function version () {echo' desktop! ';} Public function work () {echo' runs XP on the workstation! ';}} Class person {public function _ run ($ type) {echo 'this person's'; $ type-> Version (); $ type-> Work () ;}/// the principle of polymorphism is that all classes have been written ~ Do not modify it ~ As long as the call parameter changes outside the class, // the final result will also be modified, then this is the polymorphism $ notecomputer = new notecomputer (); $ your topcomputer = new your topcomputer (); $ person = new person (); $ person-> _ run ($ notecomputer); // object reference transfer, holding the echo '<br/>' of the other party '; $ person-> _ run ($ your topcomputer);?>

 

Small examples of Polymorphism

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.