zoukankan      html  css  js  c++  java
  • php类与对象综合案例

    <?php
    //类常量的定义与访问
    class Stu
    {
        private $name;
        private $sex;
        private $age;
    
        private static $count = 0;
        const COUNTY = '我们共同的家园---中国';
    
        public function __construct($name2,$sex2,$age2)
        {
            $this->name = $name2;
            $this->sex = $sex2;
            $this->age = $age2;
            self::$count++;//总数加加
           $this->info();
        }
        public function info()
        {
            $str = '<h2>'.self::COUNTY.'</h2>';
            $str .= "我的姓名是".$this->name.'<br>';
            $str .= "我的性别是".$this->sex.'<br>';
            $str .= "我的年龄是".$this->age.'<br>';
            $str .= $this->name.'加入中国,总共有'.self::$count.'个人';
            echo $str;
        }
        public function __destruct()
        {
            self::$count--;//总数减减
        }
    }
    
    $obj = new Stu('明哥哥','男',26);
    $obj2 = new Stu('明哥哥2','男',26);
    unset($obj2);
    $obj3 = new Stu('明哥哥3','男',26); $obj4 = new Stu('明哥哥4','男',26);

  • 相关阅读:
    Python多版本共存
    Windows下安装glumy过程
    安卓手机刷机
    动态规划学习
    Linux下载源
    背包问题扩展
    mongol学习
    云爬虫测试
    arc的安装
    Centos
  • 原文地址:https://www.cnblogs.com/xm666/p/11255391.html
Copyright © 2011-2022 走看看