Praktikum PBO D 2026/Week 1: Class, Object, & Constructor/Live Coding

Live Coding

Main.java

class Vehicle {
    String name;
    int wheelCount;
    float normalPrice;

    Vehicle(String name, int wheelCount, float normalPrice) {
        this.name = name;
        this.wheelCount = wheelCount;
        this.normalPrice = normalPrice;
    }

    Vehicle(String name) {
        this.name = name;
        this.wheelCount = 4;
        this.normalPrice = 0;
    }
        
    Vehicle() {
    }
}

public class Main {
    public static void main(String[] args) {
        Vehicle esemkaReborn = new Vehicle("Esemka Reborn GT-R Liberty Walk RWB", 3, 19000);
        Vehicle shogunRWB = new Vehicle("Shogun RWB", 2, 9000);
        Vehicle yarisGR = new Vehicle("Yaris GR");

        System.out.println(yarisGR.name + " Vrooom vrooom");
    }
}