Home > Backend Development > PHP Tutorial > PHP interface and abstract class (abstract)_PHP tutorial

PHP interface and abstract class (abstract)_PHP tutorial

WBOY
Release: 2016-07-13 10:30:30
Original
907 people have browsed it

interface

defines an interface class, and the methods in it must be implemented by subclasses. An interface is a template for a class, and its subclasses must implement all methods defined in the interface.

interface User{

function getHeight($height);

function getWeight($weight);

}

class my implements User{

function getHeight($username){

echo $height;

}

function getWeight($weight){

echo $weight;

}

}

abstract

Abstract class extracts the analogous part, Just write repetitive things into abstract classes to reduce the workload. As long as the method is not declared abstract, it does not need to be implemented in its subclasses. And this method is a public method in the subclass.

abstract User{

abstract function getHeight($height);

function getWeight(){

echo $weight;

}

}

class my extends User{

function getHeight($height){

echo $height;

}

function getInfoById($id){

$this->getWeight."
";

echo $id;

}

}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/765244.htmlTechArticleinterface defines an interface class, and the methods in it must be implemented by its subclasses. An interface is a template for a class, and its subclasses must implement all methods defined in the interface. interface User{...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template