/** * Diese Klasse ist ein Konto ohne Überziehungsmöglichkeit * @author tom eicher */ public class Konto1 { protected int betrag; public String inhaber; /** * Führt eine Buchung durch. * Keine Überziehung erlaubt, * @param wert Positive Zahl = Einzahlung; * Negative Zahle = Abhebung */ public void buchen(int wert) { if (betrag+wert < 0) return; betrag += wert; } public int getBetrag() { return betrag; } public static void main(String[] x) { Konto1 k1 = new Konto1(); k1.betrag=100; System.out.println("Kontostand "+k1.getBetrag()); k1.buchen(50); System.out.println("Kontostand "+k1.getBetrag()); k1.buchen(-500); System.out.println("Kontostand "+k1.getBetrag()); Konto1 k2 = new Girokonto(); System.out.println("Kontostand "+k2.getBetrag()); k2.buchen(50); System.out.println("Kontostand "+k2.getBetrag()); k2.buchen(-500); System.out.println("Kontostand "+k2.getBetrag()); System.out.println("k1: "+ k1.getClass().getName()); System.out.println("k2: "+ k2.getClass().getName()); } }