码迷,mamicode.com
首页 > Web开发 > 详细

20191119PHP.class类练习

时间:2019-11-19 17:07:30      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:外部   function   this   prot   不能   des   php   struct   new   

<?php
class person{
public $name;
private $age;
public $sex;
const WOMAN=0;
const MAN=1;
function __construct($name,$age){
$this->name=$name;
$this->age=$age;
}
private function run(){
echo $this->name." ran..";
}

public function eat(){
echo $this->name." eat";
}
protected function look(){
echo $this->name." look";
}

public function wc(){
echo $this->name." go to wc";
}
}

//$tom=new person("tom",30);
//$tom->eat();//公开的外部可以用
//$tom->look();//保护的外部不可用
//$tom->run();//私有的外部不可用


//继承

class man extends person{
// final $sex="男";//final不能修饰变量;
function __construct($name,$age){
parent::__construct($name,$age);
$this->sex=$this::WOMAN;

}
public function wc(){
echo $this->name." go to manWC";
}
function __destruct(){
echo "over";
}

}
class waman extends person{
// final $sex="女";
public function wc(){
echo $this->name." go to wamanWC";
}
}


$tom=new man("tom",19);
$tom->wc();
?>

20191119PHP.class类练习

标签:外部   function   this   prot   不能   des   php   struct   new   

原文地址:https://www.cnblogs.com/syqlwyx/p/11890433.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!