Follow Baidu Learn Php[4]oop face Object Programming -12-abstract class

Source: Internet
Author: User
Tags learn php

What is an abstract method? The method that we define in the class without the method body is an abstract method. The so-called no method body refers to the method declaration when there is no curly braces and the contents of it, but directly at the declaration of the method name after the end of the semicolon, and in the declaration of the abstract method also add a keyword "abstract" to decorate.

Catalogue ====================================

1. Declaring an abstract class, abstract method (case one)

2. Inheriting an abstract class (instance two)

=======================================

Case One

<?  Abstract class test{         // declares a test abstract class public      $name ;     Abstract  Public // declaring an abstract method     Public  ?>

Example Two

<?PHPAbstract classhello{Abstract  Publicfunction Test ();}/*** */classNihao extends hello{ Publicfunction Test () {echo"Hello world\n"; }}/*** */classWohao extends hello{ Publicfunction Test () {echo"I want to become Daniel! "; }} $a=NewNihao; $a-test ();?>
The output reads as follows:
Hello World

The END

Follow Baidu Learn Php[4]oop face Object Programming -12-abstract class

Related Article

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.