66 lines
1.4 KiB
PHP
66 lines
1.4 KiB
PHP
<?php
|
|
|
|
class SportObject
|
|
{
|
|
public string $name;
|
|
public int $age;
|
|
public float $weight;
|
|
public string $sex;
|
|
public float $height;
|
|
|
|
/**
|
|
* @param string $name
|
|
* @param int $age
|
|
* @param string $sex
|
|
* @param float $weight
|
|
* @param float $height
|
|
*/
|
|
public function __construct(string $name, int $age, string $sex, float $weight = 0.0, float $height = 0.0)
|
|
{
|
|
$this->name = $name;
|
|
$this->age = $age;
|
|
$this->weight = $weight;
|
|
$this->sex = $sex;
|
|
$this->height = $height;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
function showMe(): string
|
|
{
|
|
return '这是父类的showMe方法';
|
|
}
|
|
|
|
}
|
|
|
|
class BeatBasketBall extends SportObject
|
|
{
|
|
function showMe(): string
|
|
{
|
|
if ($this->height > 185) {
|
|
return $this->name . '符合要求';
|
|
} else {
|
|
return $this->name . '不符合要求';
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
class WeightLifting extends SportObject
|
|
{
|
|
function showMe(): string
|
|
{
|
|
if ($this->weight < 85) {
|
|
return $this->name . '符合要求';
|
|
} else {
|
|
return $this->name . '不符合要求';
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
$beatBasketBall = new BeatBasketBall(name: '科技', age: '18', sex: '男', height: 190);
|
|
$weightLifting = new WeightLifting(name: '明日', age: 20, sex: '男', weight: 80, height: 185);
|
|
echo $beatBasketBall->showMe().'<br>';
|
|
echo $weightLifting->showMe().'<br>'; |