Eine gute Antwort wäre:

Die Anzahl, wie oft ein einzelnes Objekt verwendet wurde. (Wenn das nicht klar ist, betrachten Sie noch einmal die Klassendefinition, um zu sehen, dass die Variable zaehler Teil eines jeden Objekts ist und, dass jedes Objekt seine eigene Methode inkrementZaehler() hat, die ihre eigene Variable inkrementiert.)

Beispiel main()

Hier ist die main() Methode, die dieses Konzept zeigt:

class Bankkonto
{
  private String kontonummer;
  private String kontoinhaber;
  private int    kontostand;
  private int    zaehler = 0;

  Bankkonto( String ktoNummer, String ktoInhaber, int start ) { . . . . }
  private void inkrementZaehler() { . . . . }
  int aktuellerKontostand() { . . . . }
  void  verarbeiteEinzahlung( int betrag ) { . . . . }
  void verarbeiteAuszahlung( int betrag ) { . . . . }
  void anzeigen() { . . . . }

}

class BankkontoTester
{
  public static void main( String[] args )
  {
    Bankkonto bobsKonto  = new Bankkonto( "999", "Bob", 100 );
    Bankkonto jillsKonto = new Bankkonto( "111", "Jill", 500 );

    bobsKonto.verarbeiteAuszahlung( 50 );
    bobsKonto.verarbeiteEinzahlung( 150 );
    bobsKonto.verarbeiteAuszahlung( 50 );

    jillsKonto.verarbeiteEinzahlung( 500 );
    jillsKonto.verarbeiteAuszahlung( 100 );
    jillsKonto.verarbeiteAuszahlung( 100 );
    jillsKonto.verarbeiteEinzahlung( 100 );

    bobsKonto.anzeigen();
    jillsKonto.anzeigen();
  }
}

FRAGE 12:

Was wird das Programm ausgeben?

Inhaltsverzeichnis