Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- // membuat kelas dengan user
- class User {
- //property
- public $nama;
- public $ttl;
- public $jk;
- public $alamat;
- public $pekerjaan;
- public $hobi;
- public $goldarah;
- // membuat method
- function setNama( $name ) {
- $this->nama = $name;
- return;
- }
- function getNama() {
- return $this->nama;
- }
- function setTtl( $tempat ) {
- $this->ttl = $tempat;
- return;
- }
- function getTtl() {
- return $this->ttl;
- }
- function setJk( $jk ) {
- $this->jk = $jk;
- return;
- }
- function getJk() {
- return $this->jk;
- }
- function setAlamat( $Alamat ) {
- $this->alamat = $Alamat;
- return;
- }
- function getAlamat() {
- return $this->alamat;
- }
- function setPekerjaan( $pekerjaan ) {
- $this->pekerjaan = $pekerjaan;
- return;
- }
- function getPekerjaan() {
- return $this->pekerjaan;
- }
- function setHobi( $hobi ) {
- $this->hobi = $hobi;
- return;
- }
- function getHobi() {
- return $this->hobi;
- }
- function setGd( $Goldarah ) {
- $this->goldarah = $Goldarah;
- return;
- }
- function getGd() {
- return $this->goldarah;
- }
- }
- /* membuat object */
- $datadiri = new User;
- /* memanggil object methods */
- $datadiri->setNama( 'Cristofel Recky' );
- $datadiri->setTtl( 'JAKARTA / 10-11-1990' );
- $datadiri->setJk( 'Laki - Laki' );
- $datadiri->setAlamat( 'JAKARTA' );
- $datadiri->setPekerjaan( 'MAHASISWA' );
- $datadiri->setHobi( 'Olahraga' );
- $datadiri->setGd( 'A' );
- echo "Nama : ".$datadiri->getNama().'<br />';
- echo "TTL : ".$datadiri->getTtl().'<br />';
- echo "Jenis Kelamin : ".$datadiri->getJk().'<br />';
- echo "Alamat : ".$datadiri->getAlamat().'<br />';
- echo "Pekerjaan : ".$datadiri->getPekerjaan().'<br />';
- echo "Hobi : ".$datadiri->getHobi().'<br />';
- echo "Golongan Darah : ".$datadiri->getGd().'<br />';
- ?>
Add Comment
Please, Sign In to add comment