Abstract class, interface definition in PHP

Source: Internet
Author: User

Abstract class:

1) A class that contains at least one abstract function. In other words, any class has only one or more abstract methods, and this class is an abstract class.

2) There can be specific methods in an abstract class, and you can have member variables .

3) Abstract classes cannot be instantiated . is called abstract, but also how to instantiate. 2333.

4) Usage:

    abstract class father{

      the protected (or public modifier cannot be private or the subclass cannot get it) abstract function func1 ();

}

When implementing an abstract method that inherits to

Class Son extends father{// as with normal classes, a subclass can inherit only one abstract class

Public (remove abstract keyword) function func1{

Echo ' must implement all the abstract methods ';

}

}

Interface (interface):

1) All of the interfaces are abstract methods . (because it is intended to be implemented for subclasses.) So it's all public. )

2) There can be no specific method in the interface, and there can be only member constants .

3) A class can implement multiple interfaces .

3) Usage: implements the keyword to implement multiple interfaces separated by commas.

Class Son implements INTERFACEA,INTERFACEB,INTERFACEC {

1. Implement all the abstract methods of these three interfaces, 2. To exactly match the parameters of the abstract method 3. The constants of an interface cannot be overwritten .

}

  

Abstract class, interface definition in PHP

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.