Membangun dari awal

Oleh dekifebrian7 78 0 pada Sabtu, 21 April 2018, 20:24:28


Kembali ke forum soal ini

#php #pemograman-berorientasi-objek-di-php #dasar-pemograman-berorientasi-objek-pbo-di-php


Petunjuk Diskusi
Silahkan masuk untuk berdiskusi



Ini salahnya dimana gan. keterangannya metode ambil_foto() belum saya tambahkan.
class Handphone {
  public $kamera;
  public $tahun;
  public $layar_sentuh = true;
  
  public function __construct($kamera, $tahun){
    $this->kamera = $kamera;
    $this->tahun = $tahun;
  }

	public function ambil_foto(){
  		return "$this->kamera jepret..!!";
		}
	} 
 
$canggih = new handphone ($kamera = "8 megapixels", $tahun = 2013);
$jadul = new handphone ($kamera = "2 megapixels", $tahun = 2012);

$jadul->layar_sentuh = false;
echo $canggih->ambil_foto();
0 jempol




ZihxS
300
816
· 6 tahun yang lalu · 0 jempol

Coba kode ini :

class Handphone {
  public $kamera;
  public $tahun;
  public $layar_sentuh = true;

  public function __construct($kamera,$tahun){
    $this->kamera = $kamera;
    $this->tahun = $tahun;
  }
  public function ambil_photo() {
    return "$this->kamera jepret..!!";
  }
  public function tahun_hp() {
    return "HP Ini tahun $this->tahun";
  }
}
$canggih = new Handphone("Kamera : 8 Megapixels","Tahun : 2013");
$jadul = new Handphone("Kamera : 2 Megapixels","Tahun : 2012");

$jadul->layar_sentuh = false;

echo $canggih->ambil_photo();
echo $jadul->tahun_hp();

cybersec
211
2
· 5 tahun, 11 bulan yang lalu · 0 jempol

//perasaan gw di soal kaga ada disuruh cetak tahun hp nya

//jd gw cukup gini aja jalan ko..

//jgn lupa perhatiin setelah notasi panah ngga ada lg tanda "$"

class Handphone {
  public $kamera;
  public $tahun;
  public $layar_sentuh = true;
  
  public function __construct($kamera, $tahun) {
    $this->kamera=$kamera;
    $this->tahun=$tahun;
  }
  public function ambil_photo() {
    return "$this->kamera jepret..!!";
  }
  
}

$canggih = new Handphone("Kamera: 8 Megapixels", "Tahun : 2013");
$jadul = new Handphone("Kamera: 2 Megapixels", "Tahun : 2012");

$jadul->layar_sentuh=false;
echo $canggih->ambil_photo();