Equality / aliasing 1
=====================

``` {.java}
Dog dog1 = new Dog("Wally");
Dog dog2 = dog1;

dog1.setName("Lee");
```

`dog1 == dog2`? And, `dog1.equals(dog2)`?

a.  *`true`, `true`*
b.  `true`, `false`
c.  `false`, `true`
d.  `false`, `false`

Equality / aliasing 2
=====================

``` {.java}
Dog dog1 = new Dog("Lee");
Dog dog2 = dog1;

dog2.setName("Wally");
dog2 = new Dog("Wally");
```

`dog1 == dog2`? And, `dog1.equals(dog2)`?

a.  `true`, `true`
b.  `true`, `false`
c.  *`false`, `true`*
d.  `false`, `false`

Variable scope
==============

``` {.java}
public class Foo {
  int x = 10;
  public void bar(int x) {
    System.out.println(x);
  }
}
```

Elsewhere, `Foo f = new Foo(); f.bar(7);`\
What is output?

a.  Nothing; this code won't compile.
b.  10
c.  *7*
d.  A `NullPointerException` is thrown.

Class members
=============

``` {.java}
public class Foo {
  public static final int BAR = 100;
}
public class Baz {
  public void qux() {
    ...    
```

How might I obtain the value of `BAR` in `qux()`?

a.  `Foo f = new Foo(); int x = f.BAR;` *note: this is correct, but a
    bad idea*
b.  It is not possible to access `final` variables from other classes.
c.  *`int x = Foo.BAR;`*
d.  `int x = Foo().bar`

Runtime
=======

Suppose you have $n$ spots in line for containers, and $n - 1$ of them
are already filled, in order by departure time.

A new container arrives and you want to add it in order to your
collection. What is the best and worst case for the number of existing
containers you must move to keep them sorted (best, worst)?

a.  0, 1
b.  0, $n / 2$
c.  $n$, $n$
d.  *0, $n - 1$*
e.  1, $n - 1$

Chains
======

``` {.java}
public class Chain {
  private int contents;
  private Chain next;
  
  public int foo() {
    if (next == null) return contents;
    return contents + next.foo();
  }
}
```

This method:

a.  *returns the sum of the `contents` in the chain.*
b.  won't compile
c.  always returns 0
d.  raises a `NullPointerException`

Loops
=====

Which of these loops takes constant time, independent of n?

a.  `for (int i=0; i<n; i++) {...`
b.  `for (int j=3; j<n-3; j++) {...`
c.  *`for (int k=n; k<n+5; k++) {...`*
d.  each takes more than constant time

Largest value
=============

For very large $n$, which of the following will have the largest value?

a.  $a(n) = n + 400000$
b.  *$b(n) = 25n^2 + 2000(\log\ n)^5$*
c.  $c(n) = 24n^2 + 100000n$*
d.  $d(n) = 300n\ \log\ n$

Runtime
=======

``` {.java}
public void foo(int n) {
  for (int i=0; i<n; i++) {
    bar(i);
  }
  for (int i=0; i<n; i++) {
    baz(i);
  }
}
```

If `bar()` and `baz()` each take a constant number of steps, how does
the runtime of `foo()` grow?

a.  independent of `n`
b.  *linear with `n`*
c.  quadratic in `n`
d.  exponential in `n`

