Advertisement
aldinokemal

Kelas - Constructor

Sep 25th, 2022
1,193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class Persegi
  4. {
  5.     private $panjang;
  6.     private $lebar;
  7.  
  8.     public function __construct($p, $l)
  9.     {
  10.         $this->panjang = $p;
  11.         $this->lebar = $l;
  12.     }
  13.  
  14.     public function luas()
  15.     {
  16.         return $this->panjang * $this->lebar;
  17.     }
  18.  
  19.     public function keliling()
  20.     {
  21.         return 2 * ($this->panjang + $this->lebar);
  22.     }
  23. }
  24.  
  25. $persegi = new Persegi(5, 4);
  26. echo $persegi->luas();
  27. echo $persegi->keliling();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement