Php abstract method and abstract class instance analysis, php abstract class instance analysis

Source: Internet
Author: User

Php abstract method and abstract class instance analysis, php abstract class instance analysis

This example describes php abstract methods and abstract classes. We will share this with you for your reference. The details are as follows:

What is an abstract method?

The method defined in the class without a method body is an abstract method. There is no braces and content in the method declaration. In addition, when declaring an abstract method, the keyword abstract is also added.

For example:

Abstract function fun1 (); abstract function fun2 ();

As long as there is an abstract method in the class, this class must be defined as an abstract class.

Abstract classes should also be modified with abstract.

Abstract classes can have non-Abstract methods and member attributes.

However, as long as there is an abstract method, this class must be defined as an abstract class.

How to use abstract classes? The most important thing is the abstract class, which cannot generate instance objects!

Defining an abstract class is equivalent to defining a standard! This specification requires sub-classes to comply with it! After the subclass inherits the abstract class, the abstract methods in the abstract class are implemented according to the requirements of the subclass.

The subclass must implement all the abstract methods in the abstract class. Otherwise, there are still abstract methods in the subclass, subclass or abstract class, or they cannot be instantiated!

<? Phpabstract class Demo {var $ test; abstract function fun1 (); abstract function fun2 (); function fun3 (){...}} class Test extends Demo {function fun1 (){...} function fun2 (){...}} $ test = new Test ();?>

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.