标签:php初学者
今日课程:PHP开发-零基础到精通疯狂实战教程(第二季)【韦玮老师】
1.继承与封装的实战
/*封装*/ class woman{ var $name; var $age; private $money;//给money赋值 function setm($b){ $this->money=$b; } function money1(){ echo ‘my money is‘.($this->money).‘<br>‘; } } $a = new woman(); $a ->name; //$a ->money;无法访问 //$a ->money1();可以正常访问 //$a ->money1();无法访问 $a ->setm(999); $a ->money1();
/*继承*/ class woman{ var $name; var $age; function ect(){ echo "i can eat<br>"; } } class man extends woman{ function sing(){ echo ‘i cam sang<br>‘; } } class ren extends man{ } $a = new man(); $a -> ect(); $a -> sing(); $b = new ren(); $b -> ect(); $b -> sing();
/*重载*/ class woman{ var $name; var $age; function eat(){ echo "i can eat<br>"; } } class ren extends woman{ function eat(){ echo ‘i can 大口吃<br>‘; } } $a = new ren(); $a -> eat();//重载方法
本文出自 “一条大大大大废鱼” 博客,谢绝转载!
标签:php初学者
原文地址:http://lonelyman.blog.51cto.com/9706318/1954951