Created
February 24, 2024 17:38
-
-
Save rizkytegar/43a83ac0932d9e38ac9cfad65d17c06c to your computer and use it in GitHub Desktop.
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 | |
// Definisikan kelas 'Person' | |
class Mahasiswa { | |
// Properties atau atribut | |
public $name; | |
public $nim; | |
// Constructor untuk menginisialisasi objek | |
public function __construct($name, $nim) { | |
$this->name = $name; | |
$this->nim = $nim; | |
} | |
// Method untuk menampilkan informasi tentang objek Person | |
public function introduce() { | |
// mengembalikan nilai | |
return "Nama: " . $this->name . ", Nim: " . $this->nim; | |
} | |
} | |
// Membuat objek dari kelas 'Person' | |
$mahasiswa1 = new Mahasiswa("Dwi", 30); | |
$mahasiswa2 = new Mahasiswa("Wahyu", 25); | |
// Memanggil method pada objek | |
echo $mahasiswa1->introduce(); | |
echo "\n"; | |
echo $mahasiswa2->introduce(); | |
echo "\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment