#php #pemograman-berorientasi-objek-di-php #dasar-pemograman-berorientasi-objek-pbo-di-php
Petunjuk Diskusi
Anda belum mencetak ambil_photo() dari $canggih
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 ("8 Megapixel", 2013);
$jadul = new Handphone ("2 Megapixel", 2012);
$jadul->layar_sentuh=false;
echo $canggih->ambil_photo();
0 jempol
rizky180894
205
8
·
7 tahun, 3 bulan yang lalu
·
0 jempol
kaya nya udh benar , tpi mungkin data di dalam variable $canggih nya kurang lengkap ,, baca lgi instruksi nya , jgn sampe ada syntax yg terlewat ,, coba bedakan >>
1.class handphone {
2. public $kamera;
3. public $tahun;
4. public $layar_sentuh = true;
5.
6. public function __construct($kamera,$tahun){
7. $this->kamera = $kamera;
8. $this->tahun = $tahun;
9. }
10. public function ambil_photo() {
11. return "$this->kamera jepret..!!";
12. }
13.}
14.$canggih = new handphone("kamera : 8 megapixels", "Tahun : 2013");
15.$jadul = new handphone("kamera ,:2 megapixels", "Tahun : 2012");
16.$jadul->layar_sentuh = false;
17.echo $canggih->ambil_photo();
rizky180894
205
8
·
7 tahun, 3 bulan yang lalu
·
1 jempol
string nya harus lengkap sperti yg ada di instruksi nya