【问题标题】:Adding Speak Methods [closed]添加说话方法[关闭]
【发布时间】:2015-09-19 16:24:18
【问题描述】:

如何在下面的 Dog 类中添加 speak 方法。 我正在尝试让狗能够吠叫。

<?php
class Dog
{
    private $dog_weight = 0;
    private $dog_breed = "no breed";
    private $dog_color = "no color";
    private $dog_name = "no name";



function display_properties()
{



    print "Dog weight is $this->dog_weight. Dog breed is $this->dog_breed.     Dog color is $this->dog_color.";


}
}
?>

【问题讨论】:

标签: php class methods easyphp


【解决方案1】:

不确定您是否因为问题的基本性质而被否决,但基本上您只需要:

  • 在类上创建公共方法
  • echo(或上面提到的print)你希望 Dog 类说的内容

查看"Defining Class Methods" section on this tutorial 以获得简单的概述。

【讨论】:

    猜你喜欢
    • 2014-05-25
    • 1970-01-01
    • 1970-01-01
    • 2013-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多