Suppose that we say:

Cons lst = null;
for (int i = 0; i < 3; i++ )
    lst = cons( i, lst );

What is the runtime type of first(lst)?

  • A: int
  • B: Integer
  • C: null
  • D: Cons
  • E: Object

    Answer: B

    The declared type of first(lst) is Object. When this code says cons(i, lst), the compiler coerces the int value i into the reference type Integer. Integer (a subtype of Object) is what first(lst) actually is at runtime.

    Contents    Page-10    Prev    Next    Page+10    Index