Advertisement
yoshoo

Untitled

Aug 25th, 2019
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 KB | None | 0 0
  1. <?php
  2.  
  3. class Produk {
  4.     public $judul,
  5.            $penulis,
  6.            $penerbit,
  7.            $harga;
  8.  
  9.     public function __construct($judul = "judul", $penulis = "penulis", $penerbit = "penerbit", $harga = "0") {
  10.         $this->judul = $judul;
  11.         $this->penulis = $penulis;
  12.         $this->penerbit = $penerbit;
  13.         $this->harga = $harga;
  14.     }
  15.  
  16.     public function getLabel() {
  17.         return "$this->penulis, $this->penerbit";
  18.     }
  19. }
  20.  
  21. $produk1 = new Produk("Naruto", "Masashi Kishimoto", "Shonen Jump", 30000);
  22. $produk2 = new Produk("Uncharted", "Neil Druckmann", "Sony Computer", 250000);
  23. $produk3 = new Produk("Dragon Ball");
  24.  
  25. echo "Komik : " . $produk1->getLabel();
  26. echo "<br>";
  27.  
  28. echo "Game : " . $produk2->getLabel();
  29. echo "<br>";
  30.  
  31. var_dump($produk3);
  32.  
  33. echo "<br>";
  34. echo "Barang : " . $produk3->getLabel();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement