Created
November 7, 2012 22:46
-
-
Save gregbarcza/4035067 to your computer and use it in GitHub Desktop.
OOP feladat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
TOVÁBBI INFÓ AZ ABSTRACT CLASSRÓL: | |
http://aleembawany.com/2010/04/03/understanding-abstract-classes-in-php/ | |
* | |
*/ | |
abstract class Jarmu { | |
function fogyasztas() { | |
$fogy = $this->fogy()." l/100km"; | |
return strtoupper($fogy); | |
} | |
function sebesseg() { | |
$fogy = $this->seb()." km/h"; | |
return strtoupper($fogy); | |
} | |
abstract function seb(); | |
abstract function fogy(); | |
} | |
class Repulo extends Jarmu { | |
private $sebesseg = 900; | |
private $fogyasztas=600; | |
function seb(){ | |
return $this->sebesseg; | |
} | |
function fogy(){ | |
return $this->fogyasztas; | |
} | |
} | |
class Hajo extends Jarmu { | |
private $sebesseg = 120; | |
private $fogyasztas=250; | |
function seb(){ | |
return $this->sebesseg; | |
} | |
function fogy(){ | |
return $this->fogyasztas; | |
} | |
} | |
class Gepkocsi extends Jarmu { | |
private $sebesseg = 220; | |
private $fogyasztas=10; | |
function seb(){ | |
return $this->sebesseg; | |
} | |
function fogy(){ | |
return $this->fogyasztas; | |
} | |
} | |
$rep = new Repulo(); | |
$haj=new Hajo(); | |
$kocsi=new Gepkocsi(); | |
echo "Repülő sebessége: ".$rep->sebesseg()."<br>"; | |
echo "Hajó fogyasztása: ".$haj->fogyasztas()."<br>"; | |
echo "Gépkocsi fogyasztása: ".$kocsi->fogyasztas()."<br>"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment