zoukankan      html  css  js  c++  java
  • 复习访问父类中的方法

    这节明天晚上复习完。

    每天学习或者复习一节,看起来很缓慢,可是真的坚持下来,会发现,这种缓慢的学习进程也是很快的,一本书也很快就会学完。
    坚持是一种力量,真正强大的力量,是每个人都触手可及的,但是为什么很多人却没有这种力量,原因就是他并不是发自内心地需要它。

    =========复习访问父类中的方法=======明晚写在下面==========

     1 <?php
     2   class student
     3   {
     4       var $no;
     5       var $name;
     6       var $gender;
     7       var $age;
     8       
     9       function set_data($arr)
    10       {
    11           $this->no=$arr["no"];
    12           $this->name=$arr["name"];
    13           $this->gender=$arr["gender"];
    14           $this->age=$arr["age"];
    15           }
    16           
    17           function grow($i){
    18               $this->age+=$i;
    19               }
    20       function get_data(){
    21           echo"<br />
    22   <b>学生信息</b><br />
    23   ";
    24   echo "学号:$this->no<br />
    25   ";echo "姓名:$this->name<br />
    26   ";echo "性别:$this->gender<br />
    27   ";echo "年龄:$this->age<br />
    28   ";
    29           }
    30       }
    31   
    32  class college_student extends student{
    33      var $department;
    34  
    35      function change_department($new_department){
    36          $this->department=$new_department;
    37          }
    38          
    39      function set_data($arr)
    40       {
    41 parent::set_data($arr);
    42           $this->department=$arr["department"];}    
    43           
    44         function get_data(){
    45             parent::get_data();
    46               echo "$this->name"."的所在系是$this->department<br />";
    47             
    48             
    49             }   
    50     
    51      } 
    52  $s=new college_student;
    53       $temparr=array("no"=>"001","name"=>"lisa","gender"=>"male","age"=>"22","department"=>"计算机系");
    54  
    55   $s->set_data($temparr);
    56 
    57  $s->get_data();
    58  
    59      
    60     ?>
    学生信息
    学号:001
    姓名:lisa
    性别:male
    年龄:22
    lisa的所在系是计算机系
  • 相关阅读:
    javaSE基础(三)
    javaSE基础(二)
    javaSE基础(一)
    文件目录爬虫
    前自增 与 后自增
    查找 与 排序 总结
    python 使用 grpc
    python3.7 安装 uwsgi
    go
    go
  • 原文地址:https://www.cnblogs.com/4php/p/2800592.html
Copyright © 2011-2022 走看看