zoukankan      html  css  js  c++  java
  • 14-5-19 类和对象

    类:可以理解成一个功能集合菜单,通过类来实现生成我们的方法。

    面向对象专指在程序设计中采用封装、继承、抽象等设计方法。

    面向对象的要素:1、抽象性 2、封装性 3、共享性 4、强调对象结构而不是程序结构

    面向对象的三大特点:(封装、继承、多态)缺一不可。

    封装:有相似内容的东西进行封装。

    继承:有一个父类和子类,子类不需要再写就有父类的东西。

    多态:运行时加载。

    public公开的  private私有的。

    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <?php

    class Person{
        private $name;
        private $pwd;
        private $age;

        //在初始化对象的时候该函数会自动运行
        //初始化函数
        function __construct($name,$pwd,$age){
            $this->name = $name;
            $this->pwd = $pwd;
            $this->age = $age;
        }

        public function intro(){

            echo "我的名字是:".$this->name." 我的密码是:".$this->pwd;
        }


    }

    $p1 = new Person("zhangsan","sssss",20);
    $p1->intro();

    ?>

    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <?php

    class Person{
        public $name;
        public $pwd;
        public $age;

        //在初始化对象的时候该函数会自动运行
        //初始化函数
    //    function __construct($name,$pwd,$age){
    //
    //    }

        public function intro(){

            echo "我的名字是:".$this->name." 我的密码是:".$this->pwd;
        }


    }

    $p1 = new Person();
    $p1->name = "diaosi";
    $p1->age = 18;
    $p1->pwd = "22222";

    $p1->intro();

    $p2 = new Person();
    $p2->name = "asdsad";
    $p2->age = 19;
    $p2->pwd = "44444";


    ?>

  • 相关阅读:
    log4j 配置
    membership数据库的架构
    JQuery常用方法一览
    标准http状态码[英文注释版本]
    PowerDesigner教程系列(一)概念数据模型
    ASP.NET配置文件Web.config 详细解释
    C# 特性(Attribute)
    [原创]bind DNS IP列表的精确获取
    【原创】WEP 密码破解
    【收录】Nginx 状态监控
  • 原文地址:https://www.cnblogs.com/chen1101465910/p/3741207.html
Copyright © 2011-2022 走看看