PHP abstract class, interface definition, php abstract class Interface Definition

Source: Internet
Author: User

PHP abstract class, interface definition, php abstract class Interface Definition

Abstract class ):

1) includeAt least one abstract Method(Abstract function) class. In other words, any class has only one or more abstract methods. This class is an abstract class.

2) abstract classThere can be specific methods,There can be member variables.

3) abstract classCannot be instantiated. They are all called abstract. How can they be instantiated. 2333.

4) usage:

Abstract class Father {

      Protected (or public modifier cannot be private or the subclass cannot be obtained)Abstract function func1 ();

}

When the inherited abstract method is implemented

Class Son extends Father {//Like a normal class, a subclass can inherit only one abstract class.

Public (remove abstract keywords) function func1 {

Echo'All abstract methods must be implemented';

}

}

Interface ):

1) InterfaceAll are abstract methods. (Because it is used to implement sub-classes. So all are public .)

2) InterfaceNo specific method, AndOnly member constants are allowed.

3) A ClassMultiple Interfaces can be implemented.

3) usage:Implement multiple interfaces after the implements keywordSeparated by commas.

Class Son implements InterfaceA, InterfaceB, InterfaceC {

// 1. All the abstract methods that implement these three interfaces; 2. They must be exactly the same as the parameters of the abstract method; 3. The constant of the interface cannot be overwritten.

}

  

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.