PHP learning notes -- [abstract classes and Abstract METHODS]

Source: Internet
Author: User

Introduction: This is the PHP learning notes ------ [abstract class and abstract method] Details page, introduced and PHP, related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 338758 'rolling = 'no'>

<? PHP/* abstract class ** abstract class is a special class, and the interface is a special abstract class, and polymorphism requires the use of abstract classes or interfaces ** to declare abstract classes and interfaces, and some required technologies ** abstract classes **. What are abstract methods? ** Definition: if a method in a class does not have a method body, it is an abstract method (instead of using {} and simply ending with a semicolon) * function test (); // abstract Method * function test () {}; // It is not an abstract method and has a method body, but the method body is empty. ** If a method is an abstract method, abstract must be used to modify it. ** why is an abstract method used? ** What is an abstract class? ** 1. if a class is abstracted when there is a method, this class is an abstract class ** 2. if a class is an abstract class, this class must be modified using abstract. ** 3. an abstract class is a special class because there are abstract methods in a class and others remain unchanged. You can also declare Member attributes, constants, and non-abstract methods in the abstract class ** 4. abstract classes cannot instantiate objects (an object of an abstract class cannot be created through an abstract class) ** doubt: * 1. abstract methods do not have a method body and do not know what to do (no write function) * 2. Methods and attributes in an object must be in the object's orientation. Except constants and static variables and methods, abstract classes cannot create objects, members in an abstract class cannot directly access **********. * to use an abstract class, you must use a class to inherit the abstract class. To use this subclass, that is, to allow the subclass to create objects, the subclass must no longer be an abstract class. The subclass can override the method of the parent class (add the method body to the abstract method) ** there is no method body in the abstract method, subclass must implement this method (the parent class does not write a specific implementation, but the subclass must have this method name) ** defines some specifications, let subclass implement their own functions according to these specifications * purpose: to write your ownProgram Add a module to a previously written program. (a program written by someone else cannot wait until you have developed a small module ,) * *** // abstract class demo {var $ name; // other attributes of abstract function fun () can be declared in the abstract class (); // you can declare multiple Abstract METHODS abstract function test (); // abstract method} // inherit the abstract class test extends demo {function test () {echo "the task to be completed in the subclass";} function fun () {echo "Another implementation in the subclass" ;}}$ T = new test (); $ T. test (); // can be called?>

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/338758.html pageno: 8.

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.