继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

模拟的钓鱼类,纯粹是秀一把,^_^

萝卜蛋蛋
关注TA
已关注
手记 1
粉丝 5
获赞 10

<?php

class fish {

  public function eating($food) {
      echo "Fish is eating " . $food;
  }

  public function swim() {
      echo "Fish is swimming!";
  }

}

class People {

  private $fish;
  private $food;

  public function __construct(fish $fish, $food) {
      $this->fish = $fish;
      $this->food = $food;
  }

  public function fishing() {
      $this->fish->eating($this->food);
  }

  public function getFish() {
      echo "put up the fish!";
  }

}

$jiyu = new fish();
$jiyu->swim();
echo '<hr/>';
$p = new People($jiyu, '蚯蚓');
$p->fishing();
echo "<hr/>";
$p->getFish();

打开App,阅读手记
7人推荐
发表评论
随时随地看视频慕课网APP