1. What is a Horse? 

 A Horse is a very complicated animal. 

 2. What is a Unicorn? 

 A Horse with a horn. 

 3. Why do they put bells on cows? 

 Their horns don't work.

 http://media.kohlsimg.com/is/image/kohls/1642490?wid=500&hei=500&op_sharpen=1

Java programs made of classes. 

Classes are containers, they contain: static members and a blue print. 

Blue print is meant to model something, can be instantiated, constructors are used. 

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

 // public class Example {
   public static void main(String[] args) {
     Horse a = new Horse(); 
     System.out.println( a );
     a.talk(); 
   }
 }

This runs as follows:

 Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
 > run Horse
 Horse@6af984f6
 Howdy.
 > 

 Horse = { talk(); }

 Unicorn = Horse U { sing(); }

The keywords extends is implementing the starting point of the set union. 

The class extension mechanism allows you to model in stages. 

It resembles the set union of features. 

 public class Unicorn extends Horse {
   
 } 

This already illustrates inheritance and polymorphism:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Horse a = new Horse()
> a.talk()
Howdy.
> Unicorn b = new Unicorn()
> b.talk() // by inheritance
Howdy.
> Horse c = new Unicorn() // by polymorphism
> c
Unicorn@778519c3


Next let's add the feature: 

 Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
 > Horse a = new Horse()
 > a.talk()
 Howdy.
 > a.sing()
 Static Error: No method in Horse has name 'sing'
 > Unicorn b = new Unicorn()
 > b.talk()
 Howdy.
 > b.sing()
 That's me in the unicorner...
 > Horse c = new Unicorn()
 > c.talk()
 Howdy.
 > c.sing()
 Static Error: No method in Horse has name 'sing'
 > ((Unicorn)c).sing()
 That's me in the unicorner...
 > 

But pay attention

 > Unicorn d = new Horse()
 Static Error: Bad types in assignment: from Horse to Unicorn
 > 

Set union of features do you understand set union? 

 {a, b} U {c, d, e} = {a, b, c, d, e}

How about this: 

 {a, c} U {d, c} = {a, d, c, c} or what? 

Let's see how the Horse/Unicorn example works? 

 public class Unicorn extends Horse {
   public void sing() {
     System.out.println("That's me in the unicorner..."); 
   }
   public void talk() {
     System.out.println("Bonjour"); 
   }
 }

This will lead us into dynamic method lookup. 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Horse a = new Horse()
> a
Horse@527f7193
> a.talk()
Howdy.
> a.sing()
Static Error: No method in Horse has name 'sing'
> Unicorn b = new Unicorn()
> b
Unicorn@73a32e6d
> b.sing()
That's me in the unicorner...
> b.talk()
Bonjour
> Horse c = new Unicorn()
> c
Unicorn@99c5778
> c.talk()
Bonjour


 In the last example c.talk() is acceptable because Horse c;

 But when the request reaches c its most specialized type (Unicorn) takes over: Bonjour. 

 Now for the last important thing: constructor chaining. 

 public class Horse {
   String name; // one more instance member in our blueprint  
   public void talk() {
     System.out.println("Howdy."); 
   } 
   public static void main(String[] args) {
     Horse a = new Horse();
     System.out.println( a );
     a.talk();
   }
 } 

How does this work? 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Horse a = new Horse()
> a.name
null
> Unicorn b = new Unicorn()
> b.name
null


I should customize this: 

 public class Horse {
   String name; 
   
   public void talk() {
     System.out.println("Howdy, I am " + this.name); 
   } 
   public static void main(String[] args) {
     Horse a = new Horse();
     System.out.println( a );
     a.talk();
   }
 } 


Now I have: 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Horse a = new Horse()
> a.talk()
Howdy, I am null
> a.name = "Larry"
"Larry"
> a.talk()
Howdy, I am Larry


So let's customize: 

 public class Horse {
   String name; 
   Horse(String name) {
     this.name = name;
   }
   Horse() { // [1]
             // [1] 
   }         // [1] 
   public void talk() {
     System.out.println("Howdy, I am " + this.name); 
   } 
   public static void main(String[] args) {
     Horse a = new Horse("Leslie");
     System.out.println( a );
     a.talk();
   }
 } 

This works but what if we remove the constructor at // [1] 

If we do that it stops working. 

 public class Horse {
   String name; 
   Horse(String name) {
     this.name = name;
   }
   Horse() {
     
   }
   public void talk() {
     System.out.println("Howdy, I am " + this.name); 
   } 
   public static void main(String[] args) {
     Horse a = new Horse("Leslie");
     System.out.println( a );
     a.talk();
   }
 } 


 public class Unicorn extends Horse {
   public Unicorn(String name) {
     super(name);  
   }
   public void sing() {
     System.out.println("That's me in the unicorner..."); 
   }
   public void talk() {
     super.talk(); // Howdy and the name 
     System.out.println("Bonjour"); // then the French greeting 
   }
   public static void main(String[] args) {
     Horse a = new Unicorn("James"); 
     a.talk(); // still no name
   }
 }

This runs as follows:

 Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
 > run Unicorn
 Howdy, I am James
 Bonjour
 > 

--

Attendance: 

Team 1 Justin Farrer, Kyle Riley, Kyle McWilliams, Jiahao Ye, YiQing Shi, Leanne Mroz, Glenn Kurtz, Derek Erwin 
Team 2 Nova Richardson, Olivia Pfingston, Graham Halsey, Kendall Noel, Yicheng Rong 
Team 3 Christopher Dillon, Chris Canaday, Becca Morris, Skylar Meyer, Levi Beyer, Max Thielmeyer
Team 4 Tobias Smith, Blake Sormillon, Magdalena Lara, Rui Xi, Elizabeth Crichlow 
Team 5 Yonghun Kim, Yuanyuan Tang, Chetan Chauhan, Drake White, Chad Kowaleski
Team 6 Nicolas Petrovich, Alex Koopman, Menghan Xue, Jordan Koontz, Josh Lipe-Melton 
Team 7 Mitchell Thomas, Mitch Stahlbaum, Kirk Harlow