Inheritance

Run Settings
LanguagePHP
Language Version
Run Command
<?php class Produk { public $judul; public $penulis; public $penerbit; public $harga; public $jumlahHalamn; public $waktuMain; // public $tipe; public function __construct($judul = "judul", $penulis = "penulis", $penerbit = "penerbit", $harga = 0, $jumlahHalaman = 0, $waktuMain = 0){ $this->judul = $judul; $this->penulis = $penulis; $this->penerbit = $penerbit; $this->harga = $harga; $this->jumlahHalaman = $jumlahHalaman; $this->waktuMain = $waktuMain; // $this->tipe = $tipe; } public function getLable(){ return "$this->penulis, $this->penerbit"; } public function getInfoProduk(){ $string = "{$this->tipe} : {$this->judul} | {$this->getLable()} ({$this->harga})"; // if($this->tipe == "komik"){ // $string .= "{$this->jumlahHalaman} Halaman."; // }elseif($this->tipe == "game"){ // $string .= "{$this->waktuMain} Jam."; // } return $string; } } class Komik extends Produk{ public function getInfoProduk(){ $string = "Komik : {$this->judul} | {$this->getLable()} ({$this->harga}) - {$this->jumlahHalaman} Halaman"; return $string; } } class Game extends Produk{ public function getInfoProduk(){ $string = "Game : {$this->judul} | {$this->getLable()} ({$this->harga}) ~ {$this->waktuMain} Jam"; return $string; } } class CetakInfoProduk{ public function cetak(Produk $produk){ $string = "{$produk->judul} | {$produk->getLable()}, harga = {$produk->harga}"; return $string; } } $produk1 = new Komik("Naruto", "Masashi Kihsimoto", "Shonen Jump", 35000, 100, 0); $produk2 = new Game("Harry Potter", "Jk Rowling", "Warner Bross", "250000", 0, 200); // echo $produk1->getLable(); // echo $produk2->getLable(); $cetakInfoProduk = new CetakInfoProduk(); // echo $cetakInfoProduk->cetak($produk1); // echo $cetakInfoProduk->cetak($produk2); // echo $produk1->getInfoProduk(); echo $produk2->getInfoProduk();
Editor Settings
Theme
Key bindings
Full width
Lines