PHP类与继承
2014-01-03 22:33
148 查看
<?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类的定义与继承用法实例
- PHP类继承 extends使用介绍
- php类中private属性继承问题分析
- php类的封装、继承和多态的简单理解
- PHP类的继承、重写、重写...
- PHP类实例教程(八):类的继承
- php类和命名空间介绍,成员方法和类方法,类的继承与方法重写
- php类继承的使用
- php类中private属性继承问题
- 深入探讨PHP类的继承
- php类的扩展和继承
- php类的封装、继承和多态的简单理解
- PHP类继承、接口继承关系概述
- php类的继承
- PHP类继承
- php笔记(四)PHP类和对象之对象继承
- PHP类的封装与继承详解
- PHP类继承 extends使用介绍
- java,c#,php类与继承简单比较
- PHP类的变量与成员,及其继承、访问与重写要注意的问题