<?php
class vegetables
{
var $tomato = "西红柿";
var $cucumber = "黄瓜";
}
class vegetableType extends vegetables
{
var $potato = "土豆";
var $radis = "胡萝卜";
}
$v = new vegetableType();
echo "蔬菜包括:".$v->tomato." ".$v->cucumber." ".$v->potato." ".$v->radis."<br>";
class gushi
{
public static $my_static ="一片冰心在玉壶。";
public function staticValue()
{
return self::$my_static;
}
}
print gushi::$my_static;
$gushi = new gushi();
print $gushi->staticValue();
//final定义的function不能被重写
class M1
{
public final function sum($a,$b)
{
return $a + $b;
}
}
class M2 extends M1
{
public function sum($a,$b)
{
return $a + $b;
}
}
$m = new M2();
echo $m->sum(3,5);