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

http://silo.cs.indiana.edu:8346/h212/spr2016/0222a.phps

* mahazuga: Mary Ann
* serepate: Serena
  hgarciah: Henri
* balbakr: Bakr
* ruifan: Rui
* mzelenin: Matthew
* jnp2: Jay
* zeyang: Zejun
  zhang486: Jingyun
* yiwecao: Yiwei
* rthammon: Ryan
* wang686: Jiaxing
* dweissma: Andrew
* kevcao: Kevin
  ssalmero: Salmeron, Santiago (TA)
  luo23: Yawen
* runxzhao: Runxia
* dgerman: German, Dan-Adrian (Primary Instructor)
  creba: Chris

Exam 03 

Stage 03, Stage 02 

Homework 10 

I will post Homework 11 during the break (1-2:15pm)

Minute Paper:

  * top three topics in Exam 03 you want reviewed right now

Exam will have:

  (a) three random problems from the nine 

  (b) 1-2 short answer questions like those listed 

Sorting with Comparators

Constructor Chaining 

Sorting with Comparable 

Graphics 

GUIs

Exceptions 

Mouse Events 

Timer events

Nobody wants to hear about Key Events ... 

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.

class Alpha {
  public static void main(String[] args) {
    Beta f = new Beta(3);
  }
  Alpha() {
    System.out.println(0);
  }
  Alpha(int i) {
    System.out.println(i);
  }
}
class Beta extends Alpha {
  Beta() {
    super(6);
  }
  Beta(int i) {
    super(3);
    this();
  }
}

Exam has 

  3 randomly selected (out of the 9) problems and 

  2 short answer questions (like http://silo.cs.indiana.edu:8346/c212/sum2018/0712b.html)

--

class Alpha {
  public static void main(String[] args) {
    System.out.println("... won't compile");
  } 
  public static void main() {
    System.out.println("... will not run");
  }
}

This compiles and behaves as follows: 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Alpha a = new Alpha()
> a
Alpha@75d2e863
> a.main()
... will not run
> Alpha.main()
... will not run
> Alpha.main(null)
... won't compile
> java Alpha
... won't compile


Now I make a change: 

class Alpha {
  public static void main(String[] args) {
    System.out.println("... won't compile " + java.util.Arrays.toString( args ));
  } 
  public static void main() {
    System.out.println("... will not run ");
  }
}

This also compiles and behaves like this:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Alpha.main()
... will not run 
> Alpha.main(null)
... won't compile null
> java Alpha
... won't compile []
> java Alpha how about this
... won't compile [how, about, this]


This is a variation:

class Alpha {
  public void main(String[] args) {
    System.out.println("... won't compile " + java.util.Arrays.toString( args ));
  } 
  public static void main() {
    System.out.println("... will not run ");
  }


This compiles and behaves like this:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> Alpha a = new Alpha()
> Alpha.main(new int[] { "This", "is", "interesting!" }) 
Static Error: Bad types in assignment: from String to int
> Alpha.main(new String[] { "This", "is", "interesting!" })
Static Error: No method in static Alpha with name 'main' matches this invocation
    Arguments: (String[])
    Candidate signatures: void main()
> a.main(new String[] { "This", "is", "interesting!" })
... won't compile [This, is, interesting!]


Regarding Exercise 5 the key is: both super(...) and this(...) want to be first. 

One more example:

class Alpha {
  public static void main(String[] args) {
    Beta f = new Beta();
  }
  Alpha() { 
    System.out.println("I am here."); 
  }
}
class Beta extends Alpha {
  Beta() {   // this is 
    super(); // the default
             // no-arg 
  }          // constructor (or, rather, how it looks: notice the super()).
}

This compiles and prints "I am here."

class Alpha {
  public static void main(String[] args) {
    Beta f = new Beta();
  }
  Alpha() { 
    System.out.println("I am here."); 
  }
}
class Beta extends Alpha {

}

This is the proof for the statement above. 

--

class Alpha {
  public static void main(String[] args) {
    Beta f = new Beta();
  }
  Alpha(int i) { 
    System.out.println("[4] I am here."); 
  }
  Alpha() { 
    System.out.println("[3] I am here."); 
  }
}
class Beta extends Alpha {
  Beta(int i) {
    this(); // 
    System.out.println("[2] I am here."); 
  }
  Beta() {
    System.out.println("[1] I am here."); 
  }
}

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run Alpha
[3] I am here.
[1] I am here.


--

class Alpha {
  public /* static */ Alpha special = new Alpha(); 
  public static void main(String[] args) {
    Beta f = new Beta();
  }
  Alpha(int i) { 
    System.out.println("[4] I am here."); 
  }
  Alpha() { 
    System.out.println("[3] I am here."); 
  }
}
class Beta extends Alpha {
  Beta(int i) {
    this(); // 
    System.out.println("[2] I am here."); 
  }
  Beta() {
    // this(); 
    System.out.println("[1] I am here."); 
  }
}

--

class Alpha {
  public static void main(String[] args) {
    Beta f = new Beta(8);
  }
  Alpha(int i) { 
    System.out.println("[4] I am here."); 
  }
  Alpha() { 
    System.out.println("[3] I am here."); 
  }
}
class Beta extends Alpha {
  Beta(int i) {
    this(); // 
    System.out.println("[2] I am here."); 
  }
  Beta() {
    this(5); 
    System.out.println("[1] I am here."); 
  }
}

--