PHP面向对象的继承

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<?php
class Person
{
function __construct($name, $sex)
{
$this->name = $name;
$this->sex = $sex;
} function showName()
{
echo $this->name;
} function showSex()
{
echo $this->sex;
} } /**
* 子类
*/
class Teacher extends Person
{ function __construct($name, $sex, $job)
{ parent::__construct($name, $sex);
$this->job = $job;
} function showJob()
{
echo $this->job; }
} //$p1 = new Person('刘一', '男'); $laowang = new Teacher('老王', '男', '老师');
// $p1->showSex();
// $laowang->showJob();
$laowang->showSex();
$laowang->showName();
?>
</body>
</html>

  

上一篇:WPF ScrollViewer(滚动条) 自定义样式表制作 再发一套样式 细节优化


下一篇:Html中自定义鼠标的形状