This episode covers OOP basics and class design: the concepts of objects and classes, encapsulation with accessors and mutators, inheritance, polymorphism, abstract classes, and modern interfaces with default methods, static methods, and functional interfaces.

This is the core of the entire Java language: Object-Oriented Programming. Episode 6 covers OOP basics and class design — how Java models the real world into objects that have data and behavior. This concept is not just a feature; it is a way of thinking that shapes the entire Java ecosystem.
You will learn encapsulation to protect data, inheritance and polymorphism to build class hierarchies, abstract classes as frameworks, and modern interfaces for designing contracts. After this episode, you will design classes that are clean and easy to maintain.
A class is a blueprint that defines attributes and behavior. An object is a real instance of that class. A simple example:
public class Produk {
String nama;
double harga;
void tampilkan() {
System.out.println(nama + " seharga " + harga);
}
}To create an object, use the new keyword:
Produk kopi = new Produk();
kopi.nama = "Kopi Arabika";
kopi.harga = 45000;
kopi.tampilkan();new Produk() allocates an object on the heap and calls the default constructor.
Encapsulation wraps data so it can only be accessed through controlled methods. Fields are made private, then read through accessors (getters) and modified through mutators (setters):
public class Rekening {
private double saldo;
public double getSaldo() {
return saldo;
}
public void setor(double jumlah) {
if (jumlah > 0) {
saldo += jumlah;
}
}
}With a mutator, you can add validation — a negative deposit is rejected. This is an example of good class design.
Inheritance allows a class to inherit members from another class using the extends keyword. A subclass can override a parent method with @Override:
public class Kendaraan {
public void bergerak() {
System.out.println("Kendaraan bergerak");
}
}
public class Mobil extends Kendaraan {
@Override
public void bergerak() {
System.out.println("Mobil melaju");
}
}Polymorphism means one reference can point to objects of different types. The method called is determined at runtime:
Kendaraan k = new Mobil();
k.bergerak(); // memanggil versi MobilAn abstract class cannot be instantiated; it provides a framework that subclasses must complete. Abstract methods have no implementation and must be overridden:
public abstract class Bentuk {
public abstract double luas();
}
public class Persegi extends Bentuk {
private double sisi;
public Persegi(double sisi) {
this.sisi = sisi;
}
@Override
public double luas() {
return sisi * sisi;
}
}An interface defines a contract that must be implemented. Since Java 8, interfaces can have default methods (with implementations) and static methods:
public interface Pembayaran {
void bayar(double jumlah);
default void cetakStruk() {
System.out.println("Struk dicetak");
}
static void verifikasiSistem() {
System.out.println("Sistem OK");
}
}A class implementing this interface must provide bayar, but may use the built-in cetakStruk.
An interface with exactly one abstract method is called a functional interface — it becomes the basis of lambda expressions:
@FunctionalInterface
public interface Predikat {
boolean uji(int nilai);
}
Predikat lebihDariSepuluh = n -> n > 10;
System.out.println(lebihDariSepuluh.uji(25));The lambda n -> n > 10 concisely replaces an anonymous implementation. This pattern is widely used in the Stream API and modern frameworks.
Episode 6 builds the OOP foundation of Java: understanding classes and objects, applying encapsulation with accessors and mutators, building hierarchies with inheritance and polymorphism, using abstract classes as frameworks, and designing contracts with modern interfaces and functional interfaces.
Key takeaways:
new.extends; polymorphism directs calls at runtime.In the next episode, episode 7, we will discuss exception handling and basic debugging — the structure of checked and unchecked exceptions, try-catch-finally blocks, try-with-resources, rethrowing exceptions, creating custom exceptions, and debugging techniques in the IDE plus reading stack traces. Time to write robust code!