---
# System prepended metadata

title: Soal Bab 8

---

# Soal Bab 8

## 8.1 Pemrograman Berorientasi Object

![](https://i.imgur.com/RlAK3gc.png)

## 8.2 Menulis Class Sederhana

![](https://i.imgur.com/NIX8T5W.png)

![](https://i.imgur.com/TVdbOBV.png)

## 8.3 Field Instance dan Method Instance
![](https://i.imgur.com/eDrisEP.png)
![](https://i.imgur.com/ow33ghm.png)

![](https://i.imgur.com/PyvclnS.png)
![](https://i.imgur.com/fNjZ14C.png)
![](https://i.imgur.com/x5Mf0s5.png)

## 8.4 Constructor
![](https://i.imgur.com/eZ56EL3.png)
![](https://i.imgur.com/iUy56D7.png)
![](https://i.imgur.com/B8Gu6lv.png)
![](https://i.imgur.com/7JnXGu3.png)
![](https://i.imgur.com/xxCTpjj.png)
![](https://i.imgur.com/J9MwFTV.png)
![](https://i.imgur.com/gFosfsb.png)

![](https://i.imgur.com/LAuu0ej.png)
![](https://i.imgur.com/La8F2MQ.png)


## 8.5 Method Overloading dan Constructor Overloading
![](https://i.imgur.com/E6fgY3D.png)
![](https://i.imgur.com/hHoieIy.png)
![](https://i.imgur.com/npRtxqn.png)
http://ntci.on.ca/compsci/java/ch5/5_4.html

![](https://i.imgur.com/hLhu74B.png)

## 8.6 Variabel Referensi `this`

![](https://i.imgur.com/QMCsOBM.png)

1. Lengkapi class berikut:

```java
public class MyClass
{
    int a;
    int b;
    
    public MyClass(int a, int b)
    {
        {{Isi}}
        {{Isi}}
    }
    
    // ... Method-method lainnya
    
}
```

// soal this untuk panggil constructor


## 8.7 Menggunakan Object dengan Method (SOWJ 8.2 dan 8.3)
https://books.trinket.io/thinkjava/chapter10.html
![](https://i.imgur.com/SQHruQ7.png)
![](https://i.imgur.com/rjMGFMk.png)


## 8.8 Array dari Object (SOWJ 7.7)

![](https://i.imgur.com/Ug4equL.png)
![](https://i.imgur.com/F4J3w3n.png)
![](https://i.imgur.com/bKuPYvI.png)


## 8.9 Method Static
![](https://i.imgur.com/lPoSwHf.png)
![](https://i.imgur.com/wf1wcUv.png)
![](https://i.imgur.com/wNtjiQi.png)
![](https://i.imgur.com/68esmvp.png)


## Lab Activity
![](https://i.imgur.com/RYFHT8e.png)
![](https://i.imgur.com/AqIYPGK.png)
![](https://i.imgur.com/YPwbWr6.png)
![](https://i.imgur.com/HIipTKO.png)
![](https://i.imgur.com/TNNfQtj.png)
![](https://i.imgur.com/eCow7Ba.png)
![](https://i.imgur.com/1449Qao.png)
https://csawesome.runestone.academy/runestone/books/published/csawesome/Unit5-Writing-Classes/topic-5-7-static-vars-methods.html



![](https://i.imgur.com/N4JOxrF.png)



#### P8.7
```java
public class Mahasiswa
{
    String nama;
    private int totalSkor;
    private int banyakKuis;
    
    public Mahasiswa(String nama)
    {
        this.nama = nama;
        totalSkor = 0;
        banyakKusi = 0;
    }
    
    public void addSkor(int skor)
    {
        totalSkor += skor;
        banyakKuis += 1;
    }
    
    public int getTotalSkor()
    {
        return totalSkor;
    }
    
    public double getAverageSkor()
    {
        return (double) totalSkor / banyakKuis;
    }
    
}
```

![](https://i.imgur.com/oagecyr.png)





#### Note untuk Pengujian
![](https://i.imgur.com/yKaUHEG.png)
https://stackoverflow.com/questions/49259147/how-do-i-determine-if-a-field-is-private-or-protected-using-reflection-in-java/49259243