There was talk of testing the seating for the exam today. 

We will do that on Monday.

I also said I'd give you a lab that customized. 

The lab still has many points/steps but the answers are available. 

In lab you have to do several things like in assignment 6 in C211. 

This is much like the exam you will take on Wed 3/4. 

Monday we will have a review. 

I think Mardin will have another review Tuesday. 

We'll keep you informed. 

There will be one problem on the exam. 

Today:

  polymorphism

  inheritance

  dynamic method lookup 

  constructor chaining

  interfaces

  abstract classes 


class One {

}

class Two extends One {

}

So One a = new One(); is fine.

Also Two b = new Two(); is also clear. 

Now 

  One a = new Two(); 

is called polymorphism. 

I give up on some features.

I also know that this is not correct: 

  Two b = new One(); 

The class extension mechanism is like the set union of features. 

It gives inheritance. 

It also gives dynamic method lookup when features have the same name.

class Horse {
  public String toString() {
    return "I am a Horse.";  
  }
  void talk() {
    System.out.println("Howdy.");  
  }
}

class Unicorn extends Horse {
  public String toString() {
    return "I am a Horse with a horn.";  
  }
  void sing() { // that's my horn 
    System.out.println("That's me in the (uni)corner.");     
  }
  void talk() {
    System.out.println("How do you do in French.");  
  }
}

class Pegasus extends Horse {
  public String toString() {
    return "I am a Flying Horse.";  
  }
  void fly() {
    System.out.println("I hate flying.");  
  }
  void talk() {
    System.out.println("How do you do in Arabic.");  
  }
}

import java.util.*;

class Example {
  public static void main(String[] args) {
    Horse a = new Horse(); 
    a.talk(); 
    Horse b = new Unicorn(); // polymorphism 
    b.talk(); // inheritance  ]
    // b.sing(); // can't do this. why? 
    ArrayList<Horse> c = new ArrayList<Horse>();
    c.add(new Horse()); 
    c.add(new Unicorn()); 
    c.add(new Pegasus()); 
    System.out.println( c ); 
    
    System.out.println( b instanceof Horse);
    System.out.println( b instanceof Unicorn);
    
    ((Unicorn)b).sing(); 
    
    ((Pegasus)c.get(2)).fly(); 

    for (Horse h : c)
      h.talk(); // dynamic method lookup 
   
    // http://www.cs.indiana.edu/classes/c212/fall2010/notes/abstractclasses.jpg
    
  }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run Example
Howdy.
How do you do in French.
[I am a Horse., I am a Horse with a horn., I am a Flying Horse.]
true
true
That's me in the (uni)corner.
I hate flying.
Howdy.
How do you do in French.
How do you do in Arabic.
>

--