We discussed to test the seating for the exam now. 

We postpone that for Monday.

Monday we have a review. 

Mardin will also have a review Monday or Tuesday in LH102.

We will announce it in time. 

Exam next week. 

Lab this week helps you prepare. 

Originally lab was meant to be individualized. 

It now is different, the concern is for you to learn from it. 

So the lab is now more like a study guide. 

https://www.cs.indiana.edu/classes/c212-dgerman/spr2015/labSeven.html

http://www.cs.indiana.edu/classes/c212/spr2015/l7.html

The class extension mechanism allows us to model in stages:

http://www.cs.indiana.edu/classes/c212/fall2010/notes/inherit002.jpg

It gives us:

  inheritance

  polymorphism 

So we write code and eventually it leads us to this example:

http://www.cs.indiana.edu/classes/c212/fall2010/notes/abstractclasses.jpg

Abstract classes are unfinished classes (they contain promises). 

Interfaces are elements of pure design. 

Here's the code:

class Horse {
  void talk() {
    System.out.println("Howdy.");  
  }
}

class Unicorn extends Horse {
  void sing() {
    System.out.println("That's me in the (uni)corner...");  
  }
  void talk() {
    System.out.println("Howdy in French.");  
  }
}

class Pegasus extends Horse {
  void fly() {
     System.out.println("I hate flying.");  
  }
  void talk() {
     System.out.println("Howdy in Greek.");  
  }
}

import java.util.ArrayList; 

class Example {
  public static void main(String[] args) {
    Horse a = new Horse(); 
    a.talk(); 
    Horse b = new Unicorn(); // polymorphism 
    b.talk(); // inheritance 
    System.out.println( b instanceof Horse ); // true
    System.out.println( b instanceof Unicorn ); // true 
    ((Unicorn)b).sing(); 
    Horse c = new Pegasus(); 
    c.talk(); 
    // ((Unicorn)c).sing(); // error, but noticed only at run time 
    ((Pegasus)c).fly(); 
    
    ArrayList<Object> d = new ArrayList<Object>(); 
    d.add(new Horse()); 
    d.add(new Unicorn()); 
    d.add(new Pegasus()); 
    // I can store them but they won't talk to me unless I cast big pain
    
    ArrayList<Horse> e = new ArrayList<Horse>(); 
    e.add(new Horse()); 
    e.add(new Unicorn()); 
    e.add(new Pegasus()); 
    for (Horse h : e) 
      h.talk(); // dynamic method lookup 
  }
}

--