Potential project: 

http://silo.cs.indiana.edu:8346/c212/spr2015/tetris.rkt

1. What is the class extension mechanism? 

It allows you to model in stages. 

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

It functions a bit like the set union of features.

Horse = { talk() }

Unicorn = Horse U { sing() }

2. Why do we care? 

 2.1 Inheritance 

http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#toString()

class A /* extends java.lang.Object */ {
 
  public static void main(String[] args) {
    A a = new A(); 
    System.out.println( a.toString() ); // inheritance
  }
}

http://www.charlottesvilleanimalcontrol.com/wp-content/uploads/2011/10/Southern-Flying-Squirrel-Photo-Credit-Joe-McDonald2.jpg

http://zestytravel.com/wp-content/uploads/2012/04/Hand-Gliding-France-2.jpg

Maybe the second one is more of a composition. 

 2.2 Polymorphism

class A /* extends java.lang.Object */ {

  public static void main(String[] args) {
    A a = new A(); 
    System.out.println( a.toString() ); // inheritance
    
    Object b = a; // polymorphism 
      
  }
}

Real life examples: politics.

Polymorphism: ability to ignore differences for purposes related to storage. 

 2.3 Dynamic Method Lookup (Method Overriding)

class A /* extends java.lang.Object */ {
  public String toString() {
    return "This is how an A looks.";  
  }
  public static void main(String[] args) {
    Object a = new A(); 
    System.out.println( a.toString() ); // dynamic method lookup 
   
  }
}

Where did the old method go? 

class A /* extends java.lang.Object */ {
  public String toString() {
    return "This is how an A looks. " + super.toString();  
  }
  public static void main(String[] args) {
    Object a = new A(); 
    System.out.println( a.toString() ); // dynamic method lookup 
   
  }
}

 2.4 Constructor Chaining 

class A {
  A(int a) {
    System.out.println("I am receiving an: " + a); 
  }
  A() {
    // nothing here before invocation to super() or this()
    this(3); 
    System.out.println("I am in the no-arg constructor now ... ");
  }
  public static void main(String[] args) {
    A a = new A();  
    a = new A(12); 
    System.out.println( a ); 
  }
}

This isn't constructor chaining but it's a good example of implict rules. 

Java guarantees that when a new is invoked the class constructor is called.

It also guarantees that when the constructor of a subclass is invoked the 
super class constructor will run first. (When you ask for a Unicorn know that
the Horse will (have to) be created first.) 

Constructor Chaining

When you define a class, Java guarantees that the class's constructor method is called whenever 
an instance of that class is created. It also guarantees that the constructor is called when an 
instance of any subclass is created. In order to guarantee this second point, Java must ensure that 
every constructor method calls its superclass constructor method. If the first statement in a constructor 
is not an explicit call to a constructor of the superclass with the super keyword, then Java implicitly 
inserts the call super() -- that is, it calls the superclass constructor with no arguments. If the superclass 
does not have a constructor that takes no arguments, this causes a compilation error.

There is one exception to the rule that Java invokes super() implicitly if you do not do so explicitly. If 
the first line of a constructor, C1, uses the this() syntax to invoke another constructor, C2, of the class, 
Java relies on C2 to invoke the superclass constructor, and does not insert a call to super() into C1. Of 
course, if C2 itself uses this() to invoke a third constructor, C2 does not call super() either, but somewhere 
along the chain, a constructor either explicitly or implicitly invokes the superclass constructor, which is 
what is required.

Attendance: 

Haleigh, Erin   , Danielle, Shikun , Michael, Brian , Ben, 
Minh   , Grant  , Khoki   , Mahamat, Taylor , Connor, 
Shane  , Griffin, Kevin   , Brandon, Joe    , Nick  , Nick, Phoebe, and Seong In Park

class A {
  A() {
    super(); 
    System.out.println("An A is being created.");  
  }
}

class B extends A {
  B() {
    super(); 
    System.out.println(" An object of type B is being created. ");  
  }
}

class C extends B {
  C() {
    super();
    System.out.println(" An object of tyep C is being created. ");  
  }
}

class Example {
  public static void main(String[] args) {
    C c = new C(); 
    B b = new C(); 
    A a = new C(); 
    
    B d = new B(); 
    A e = new B(); 

    A f = new A(); // chaining happens but we don't see it 
  }
}

--