public class Vererbung { public static void main(String[] args) { Pasta_C p_c = new Pasta_C(); Pasta p = new Pasta(); p_c.gericht.preis_euro = 2.50F; p.preis_euro = 2.50F; Lasagne_C l_c = new Lasagne_C(); Lasagne l = new Lasagne(); l_c.pasta_c.gericht.preis_euro = 1.50F; l.preis_euro = 1.50F; } } class ItalienischesGericht { public String name; public float preis_euro; } // Wie in C: ItalienischesGericht ist eine KOMPONENTE von Pasta_C class Pasta_C { public ItalienischesGericht gericht; public int ueberbacken; public int extra_kaese; } // The OO way: Pasta ist eine ERWEITERUNG von ItalienischesGericht, und ERBT alle Variablen // seiner Basisklasse. class Pasta extends ItalienischesGericht { public int ueberbacken; public int extra_kaese; } // Das gleiche mit von Pasta_c bzw. Pasta abgleiteten Aggregationen bzw. Klassen class Lasagne_C { public Pasta_C pasta_c; public int spinat; public int bolognese; } class Lasagne extends Pasta { public int spinat; public int bolognese; }