An in-depth analysis of PHP interface and interface references _php tips

Source: Internet
Author: User
Tags abstract

1. Introduction and creation of interface
Keywords: interface
2. Reference and specification of interface
Keywords: implements
Interface: A special abstract class in which member attributes are all abstract, the same as canonical function in a program
1, the class is all abstract method
2, the abstract method without adding abstract before
3. Interface Abstract Method property is public
4, member property must be constant

Abstract:
1. There is at least one abstract method in the class
2, the abstract method needs to add abstract before

Common:
1, itself can not be instantiated, must be inherited or referenced
2. After inheriting or referencing, all abstract methods need to be overloaded before they can be used
Interfaces have their own creation keywords: interface is similar to common class creation

Copy Code code as follows:

Interface Demo {
Const name= "name";
function Fun1 ()//object method All is abstract method, front need not add adstract
function Fun2 ();
}

Interfaces can use keywords: implements multiple references and separate them with commas.
1, Common class reference interface examples:
Copy Code code as follows:

Class MyPC implements demo, Demo2, demo3{
......
}

2, abstract class Reference interface example:
Copy Code code as follows:

Abstract class MyPC implements demo, Demo2, demo3{
......
}

3, inherit the parent class reference interface Coexistence Example:
Copy Code code as follows:

Class MyPC extends Root implements demo, Demo2, demo3{
......
}

4, interface and interface inheritance:
Copy Code code as follows:

Interface Demo3 extends demo{
......
}

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.