zoukankan      html  css  js  c++  java
  • 20191119PHP.class类练习

    <?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();
    ?>

  • 相关阅读:
    数据库生成说明
    Android 的 SurfaceView 双缓冲应用
    一些and知识 和ui
    weibo11
    android总结
    weibo14
    weibo9
    weibo12
    weibo10
    在线人数的统计
  • 原文地址:https://www.cnblogs.com/syqlwyx/p/11890433.html
Copyright © 2011-2022 走看看