本文整理汇总了PHP中Car::getColor方法的典型用法代码示例。如果您正苦于以下问题:PHP Car::getColor方法的具体用法?PHP Car::getColor怎么用?PHP Car::getColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Car
的用法示例。
在下文中一共展示了Car::getColor方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Car
<?php
include 'Car.php';
$c1 = new Car('honda');
// create $c1 object
$c2 = new Car('toyota');
// create $c2 object
$c1->setColor('red');
$c2->setColor('blue');
echo $c1->getColor();
echo '<br>';
echo $c2->getColor();
示例2: Car
<?php
include 'classes/car.php';
//using public properties
$car1 = new Car();
// $car1 -> make = 'Toyota';
// echo $car1 -> make.'<br />';
//
// $car1 -> make = 'Toyota';
// $car1 -> make = 'Honda';
// echo $car1 -> make.'<br />';
//using a public method
$car1->start();
$car1->setMake('Chevy');
echo $car1->getMake() . '<br />';
//constructors
// $car2 = new Car;
$car2 = new Car('Honda', 'Accord', 'Red');
echo $car2->getColor() . '<br />';
$car3 = new Car('Honda', 'Civic', 'Blue');
echo $car3->getColor() . '<br />';
示例3: Car
echo "<p>Person: " . $bmw->buyCar() . "</p>";
// ---------Nissan sports car
echo "<hr>";
$nissanSport = Car::withPriceandMaxspeed("Nissan", false, "green", 200000, 320);
//$model, $isSportsCar, $color, $price, $maxSpeed
var_dump($nissanSport);
echo "<p> New sports car constructor used: Nissan : " . $nissanSport->getModel() . " </p>";
echo "<p> Sports car? : " . $nissanSport->getIsSportscar() . "</p>";
echo "<p> Sports car speed : " . $nissanSport->getMaxspeed() . "</p>";
$priceNissanforscrap = $nissanSport->calculateCarPriceForScrap(200);
echo "<p> The price for scrap is : " . $priceNissanforscrap . " </p>";
echo "<hr>";
//-------------------------------------------------------------------------------//
//Second Car :Mercedez
$merc = new Car("Voldemor", "mercedez-benz", "220", "silver", false);
echo "<h3>Car 2 (merc) properties: " . $merc->getColor() . "</h3>";
echo "<p>" . $merc->getModel() . "</p>";
echo "<p>" . $merc->getMaxspeed() . "</p>";
echo "<p>" . $merc->getcurrentSpeed() . "</p>";
echo "<p>" . $merc->getColor() . "</p>";
echo "<p>" . $merc->getCurrentGear() . "</p>";
//Show old speed
echo "<p> Old Speed: " . $merc->getcurrentSpeed() . " </p>";
//Change the speed
$merc->setcurrentSpeed(60);
//Show new speed
echo "<p>Changed Speed: </p>";
echo "<p>" . $merc->getcurrentSpeed() . "</p>";
//Accelerate
echo "<p>Accelerated speed : " . $merc->accelerate() . "</p> ";
//Show old gear
示例4: __construct
include "Vehicle.php";
class Car extends Vehicle
{
private $noOfDoors;
private $color;
private $brand;
public function __construct($cc, $hp, $noOfDoors, $color, $brand)
{
echo "<br/>Hi from car constructor";
parent::__construct('Car', $cc, $hp);
$this->noOfDoors = $noOfDoors;
$this->color = $color;
$this->brand = $brand;
}
public function getColor()
{
return $this->color;
}
public function getNoOfDoors()
{
return $this->noOfDoors;
}
public function getBrand()
{
return $this->brand;
}
}
$v = new Car(1.3, 100, 4, 'Golden', 'BMW');
echo "<br/>Type is " . $v->getType() . ", CC : " . $v->getCc() . ", HP : " . $v->getHp() . ", Color : " . $v->getColor() . ", Brand : " . $v->getBrand();