php 面向对象 示例,php中面向对象示例
Gun.class.php文件
php
class Gun{
//定义累的属性
public $type;
public $color;
public $bulletnum;
public $weight;
//定义类的方法
function kill(){
return"士兵".$this->type."的手枪,重量".$this->weight.",杀死了敌人!";
}
function sound(){
return "发出惨叫的声音";
}
}
?>
gun.php文件
include 'Gun.class.php';
//枪的类型
$shouqiang = new gun();
$shouqiang->type="小型";
$shouqiang->color="红色";
$shouqiang->bulletnum="20发";
$shouqiang->weight="50克";
echo $shouqiang->kill();
echo $shouqiang->sound();
?>
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
