> For the complete documentation index, see [llms.txt](https://learn.devlabss.my.id/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.devlabss.my.id/php/bab-7-php-oop-dasar/praktik-membuat-cetakan-objek-kendaraan.md).

# Praktik: Membuat Cetakan Objek Kendaraan

Praktik ini menyatukan class, object, property, method, dan inheritance.

Tujuannya adalah membangun model object yang mudah dipahami dan dikembangkan.

### Target praktik

Setelah praktik ini selesai, Anda seharusnya bisa:

* membuat class dan object
* memakai property dan method
* memahami inheritance lewat contoh sederhana

### Studi kasus

Anda diminta membuat model kendaraan.

Mulailah dari class umum, lalu turunkan menjadi class yang lebih spesifik.

### Kode latihan

```php
<?php
class Kendaraan {
    public $merk;

    public function __construct($merk) {
        $this->merk = $merk;
    }

    public function jalan() {
        echo $this->merk . " sedang berjalan";
    }
}

class Mobil extends Kendaraan {
    public function klakson() {
        echo "Tin tin";
    }
}

$mobil1 = new Mobil("Toyota");
echo $mobil1->merk;
echo "<br>";
$mobil1->jalan();
echo "<br>";
$mobil1->klakson();
?>
```

### Penjelasan singkat

Program ini menggabungkan beberapa konsep:

* `Kendaraan` sebagai parent class
* `Mobil` sebagai child class
* `$merk` sebagai property
* `jalan()` dan `klakson()` sebagai method
* constructor untuk mengisi data awal

### Hasil yang diharapkan

Program akan menampilkan merek kendaraan, lalu aksi berjalan, lalu bunyi klakson.

### Tantangan tambahan

Coba kembangkan program ini dengan:

* membuat child class `Motor`
* menambah property `warna`
* membuat method untuk menampilkan identitas kendaraan lebih lengkap

### Poin evaluasi praktik Bab 7.

Pastikan Anda sudah memahami poin berikut:

* Saya berhasil membuat class dan object.
* Saya bisa memakai property, method, dan constructor.
* Saya paham hubungan parent class dan child class.
* Saya mulai melihat manfaat OOP untuk membuat program lebih terstruktur.

Jika semua sudah jelas, lanjut ke [7.7 Checkpoint: Uji Pemahamanmu Sebelum Lanjut!](/php/bab-7-php-oop-dasar/7.7-checkpoint-uji-pemahamanmu-sebelum-lanjut.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.devlabss.my.id/php/bab-7-php-oop-dasar/praktik-membuat-cetakan-objek-kendaraan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
