zoukankan      html  css  js  c++  java
  • PHP类与继承

    <?php
      class Person
      {
      	private $name;
      	private $age;
      	
      	function __construct($name,$age){
      		$this->name = $name;
      		$this->age = $age;
      	}
      	
      	public function setName($name)
      	{
      		$this->name = $name;
      	}
      	
      	public function getName()
      	{
      		return $this->name;
      	}
      	
      	public function setAge($age)
      	{
      		$this->age = $age;
      	}
      	
      	public function getAge()
      	{
      		return $this->age;
      	}
      	
      	public function SayHello()
      	{
      		printf("<br/>name:%s,age:%d",$this->name,$this->age);
      	}
      }
      
      $person = new Person("zhangsan", 20);
      $person->SayHello();
      
      
      
      class Student extends  Person
      {
      	private $work;
      	function __construct($name,$age,$work)
      	{
      		parent::__construct($name, $age);
      		$this->work = $work;
      	}
      	
      	public function setWork($work)
      	{
      		$this->work = "学生";
      	}
      	
      	public function getWork()
      	{
      		return $this->work;
      	}
      	
      	public function Introduce()
      	{
      		printf("<br/>name:%s,age:%d,work:%s",$this->getName(),$this->getAge(),$this->getWork());
      	}
      }
      
      $student = new Student("wangwu", 18, "学生");
      $student->SayHello();
      $student->Introduce();
    ?>
    
  • 相关阅读:
    php 压缩文件 zip
    php 创建返回结果配置文件 实例
    php 生成xml文件
    php 获取读取文件内容
    基于JAVA语言的多线程技术
    Java HTTP请求
    TCP与UDP
    VC6.0 调试.dll文件
    [JNI] Java 调用 C++ dll
    HTTPS与SSL
  • 原文地址:https://www.cnblogs.com/huangzelin/p/3504363.html
Copyright © 2011-2022 走看看