Play audio slide show -- Keyboard shortcut: 'x'  Lecture overview -- Keyboard shortcut: 'u'  Previous page: Statisk og dynamisk binding i Java -- Keyboard shortcut: 'p'  Next page: Eksemplet uden dynamisk binding -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  Annotated slide -- Keyboard shortcut: 't'  Alphabetic index  Help page about these notes  Course home  Play sound for this slide -- Keyboard shortcut: 'y'    Nedarvning - slide 31 : 41

Polymorfi og dynamisk binding i Banken 

Bank3.javaSuperklassen Konto.
 

Bank3.javaSubklassen CheckKonto.
 

class Bank3 {
 
   public static void main( String[] args ) {

     Konto[] konti = new Konto[5];

     konti[0] = new Konto("Peter");
     konti[1] = new CheckKonto("Jens");
     konti[2] = new CheckKonto("Børge");
     konti[3] = new CheckKonto("Carsten");
     konti[4] = new Konto("Kristen");

     konti[0].hæv(50);                      // Peter:    -50 (Konto)
     konti[1].indsæt(100.0);                // Jens:     100 (CheckKonto)
     konti[2].indsæt(200.0);                // Børge:    200 (CheckKonto)
     konti[3].indsæt(300.0);                // Carsten
     ((CheckKonto)konti[3]).hævCheck(500);  // Carsten: -300 (CheckKonto)
     konti[4].indsæt(400.0);                // Kristen:  400 (Konto)

     for(int i = 0; i < 5; i = i + 1){
       konti[i].tilskrivRente();
     }

     for(int i = 0; i < 5; i = i + 1){
        System.out.println(konti[i]);
     }

   }
} // end Bank3