Home >Backend Development >PHP Tutorial >Introduction to PHP 8 Object Oriented 2 Abstract Class

Introduction to PHP 8 Object Oriented 2 Abstract Class

WBOY
WBOYOriginal
2016-07-28 08:26:211036browse

1. Abstract classes must be inherited to be used and cannot be directly new


2. Abstract classes can have non-abstract methods


3. Subclasses must implement all abstract methods


4. Similar to JAVA’s abstract classes

(Click to go to)JAVA's abstract class

<code><span><span><?php</span><span>//抽象类关键字 abstract  抽象类不能实例化 必须被继承才能使用</span><span>abstract</span><span><span>class</span><span>_parent</span>{</span><span>//抽象方法关键字 abstract</span><span>public</span><span>abstract</span><span><span>function</span><span>fun1</span><span>()</span>;</span><span>//抽象类中可以用非抽象方法</span><span>public</span><span><span>function</span><span>parentfunc</span><span>()</span> {</span><span>echo</span><span>"Hello<br>"</span>;
        }
    }

    <span><span>class</span><span>Test</span><span>extends</span><span>_parent</span>{</span><span>//必须实现抽象类的所有抽象方法</span><span>public</span><span><span>function</span><span>fun1</span><span>()</span>{</span><span>echo</span><span>"class Test<br>"</span>;
        }
    }


    <span>$A</span> = <span>new</span>  Test();
    <span>$A</span>->fun1();
    <span>$A</span>->parentfunc();
<span>?></span></span></code>
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces PHP Introduction 8 Object-Oriented 2 Abstract Classes, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn