note 128519 added to language.oop5.inheritance
| From: | loli at gmx dot de | Date: | Thu, 11 May 2023 04:49:07 +0000 |
| Subject: | note 128519 added to language.oop5.inheritance | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220474@lists.php.net to get a copy of this message | ||
<?php
abstract class Fahrzeug
{
protected $kennzeichen;
protected $kmStand;
protected $seitInspekt;
protected $abstandinspekt;
protected $istFrei;
protected $tagespreis;
public function __construct($kennz,$km)
{
$this->kmStand=$km;
$this->seitInspekt=$km;
$this->kennzeichen=$kennz;
$this->istFrei=TRUE;
}
public function vermieten()
{
if ($this->istFrei==TRUE)
{
echo "<p>".$this->kennzeichen." wird vermietet</p>";
$this->istFrei=FALSE;
}
else
{
echo "<p>".$this->kennzeichen." ist bereits
vermietet</p>";
}
}
public function zurueckgeben($gefKm)
{
$this->kmStand+=$gefKm;
$this->seitInspekt+=$gefKm;
if ($this->seitInspekt>$this->abstandinspekt)
{
$this->inspektion();
}
$this->istFrei=TRUE;
return "Fahrzeug erfolgreich zurueckgeben";
}
public function inspektion()
{
$this->seitInspektion=0;
echo "Inspektion durchgeführt";
}
public abstract function getMietkosten($anzTag);
}
?>
-----------------------------
<?php
class EBike extends Fahrzeug
{
private static $verfuegbar=0;
private $rahmengroesse;
public function __construct($kennz,$km,$rg)
{
parent::__construct($kennz,$km);
self::$verfuegbar++;
$this->abstandinspekt=5000;
$this->rahmengroesse=$rg;
if ($this->rahmengroesse>=26)
{
$this->tagespreis=30;
}
else
{
$this->tagespreis=20;
}
}
public static function getAnzahl()
{
return self::$verfuegbar;
}
public function getMietkosten($anzTag)
{
$kosten=$anzTag*$this->tagespreis;
return $kosten;
}
}
?>
--------------------------------------
<?php
include_once("fahrzeug.php");
include_once("ebike.php");
$test1= new EBike("MA-A-1",3600,28);
$test2= new EBike("MA-A-2",2500,26);
$test3= new EBike("MA-A-3",1000,24);
echo "<p>Anzahl an E-Bikes:".EBike::getAnzahl()."</p>";
echo "<p>".$test1->vermieten()."</p>";
echo "<p>".$test1->vermieten()."</p>";
echo "<p>".$test1->zurueckgeben(1500)."</p>";
echo "<p>".$test1->getMietkosten(3)."</p>";
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.130 (proxied: 2003:c1:f3e:1290:f899:b2cc:c511:e5a8)
----
Manual Page -- https://php.net/manual/en/language.oop5.inheritance.php
Edit -- https://main.php.net/note/edit/128519
Del: integrated -- https://main.php.net/note/delete/128519/integrated
Del: useless -- https://main.php.net/note/delete/128519/useless
Del: bad code -- https://main.php.net/note/delete/128519/bad+code
Del: spam -- https://main.php.net/note/delete/128519/spam
Del: non-english -- https://main.php.net/note/delete/128519/non-english
Del: in docs -- https://main.php.net/note/delete/128519/in+docs
Del: other reasons-- https://main.php.net/note/delete/128519
Reject -- https://main.php.net/note/reject/128519
Search -- https://main.php.net/manage/user-notes.php