zoukankan      html  css  js  c++  java
  • About_类与对象03

    php中的static

    1:属于静态变量:;

    2:是全部类的属性;

    3:调用静态变量要用::(两个冒号)。

    eg:1

     1 <html>
     2 <head>
     3     <title>static测试</title>
     4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
     5 </head>
     6 <body>
     7 <?PHP
     8 class Person{
     9 
    10     static $type = "人物";
    11     public $name = "张三";
    12     public $age = 18;
    13 
    14     public function intro(){
    15         echo Person::$type."<br/>".$this->name."<br/>".$this->age."<br/>";
    16     }
    17 }
    18 
    19 $p1 = new Person();
    20 
    21 $p1->intro();
    22 ?>
    23 </body>
    24 </html>

    eg:2

     1 <html>
     2 <head>
     3     <title>static测试</title>
     4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
     5 </head>
     6 <body>
     7 <?PHP
     8 class Person{
     9 
    10     static $type = "人物";
    11     public $name = "张三";
    12     public $age = 18;
    13 
    14     public function intro(){
    15         echo Person::$type."<br/>".$this->name."<br/>".$this->age."<br/>";
    16     }
    17 }
    18 
    19 $p1 = new Person();
    20 Person::$type = "张三不是人!";
    21 
    22 $p1->intro();
    23 ?>
    24 </body>
    25 </html>

    eg:3

    class类的继承

     1 <html>
     2 <head>
     3     <title>class类的继承</title>
     4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
     5 </head>
     6 <body>
     7 <?PHP
     8 class Person{
     9 
    10     static $type = "人物";
    11     public $name = "张三";
    12     public $age = 18;
    13 
    14     public function intro_Person(){
    15         echo $this->name."<br/>".$this->age."<br/>";
    16     }
    17 }
    18 
    19 class Teacher extends Person{
    20 
    21     public function intro_Teacher(){
    22         echo $this->age;
    23     }
    24 
    25 }
    26 
    27 class Students extends Teacher{
    28 
    29     public function intro_Students(){
    30         echo $this->age;
    31     }
    32 
    33 }
    34 
    35 $p1 = new Students();
    36 
    37 $p1->intro_Students();
    38 ?>
    39 </body>
    40 </html>
  • 相关阅读:
    声律启蒙(上 下卷,珍藏版)
    笠翁对韵(全卷,珍藏版附注释)
    Oracle 中 nvl、nvl2、nullif、coalesce、decode 函数的用法详解
    Groovy
    spring各版本jar包和源码
    Java 调用翻译软件实现英文文档翻译
    oracle导出序列的几种办法
    Oracle数据库内存使用情况分析查看
    window Maven私服搭建——nexus
    用户管理的备份与恢复
  • 原文地址:https://www.cnblogs.com/a-moemiss/p/3746627.html
Copyright © 2011-2022 走看看