package Bsp208; public class Car { // Lt Klassendiagramm /* +----------------------- | Car +----------------------- | - brand : String | - model : String | - price : float +----------------------- | + toString() : String +----------------------- */ private String brand; private String model; private float price; // Konstruktor public Car(String brand, String model, float price){ this.brand = brand; this.model = model; this.price = price; } public String getBrand() { return brand; } public String getModel() { return model; } public float getPrice() { return price; } public void setPrice(float price) { this.price = price; } // Ueberschreiben von Methode // Jede Java-Klasse hat vordefinierte Methoden @Override public String toString(){ String retValue = getBrand() + "-" + getModel() + " costs EUR " + getPrice(); return retValue; } public static void main(String[] args) { Car car = new Car("VW", "T5 Multivan", 109870.54f); // Aufruf des Konstruktors System.out.println(car); // automatisch wird car.toString() aufgerufen } }