Midterm 2, CSCI 3155
April 1st, 2004

You have 70 minutes to answer these questions.  Please read all questions before you start.  This is a closed-book exam.  Please remember that you are bound by the CU honor code.

  1. The book discusses many kinds of "bindings" used in programming languages.
    1.  [6 points] What is a "binding"?
    2. [5 points] What is a "storage binding". 
    3. [5 points] What is a "type binding".
  2. A method call in an object-oriented language (i) may be statically bound to the method implementation (text uses the term "definition" instead of "implementation"); or (ii) may be dynamically bound to the method implementation.  For this question, you may use any real language (e.g., C++ or Java) as long as you are clear about what language you are using.
    1. [10 points] Give a complete example program containing a call that is always statically bound to the method implementation.  Explain your example.
    2. [10 points] Give an example program containing a call that is dynamically bound to the method definition.  Explain your example.
    3. [10 points] Explain the difference between overriding a method and overloading a method
  3. This question concerns generic functions;
    1. [10 points] Write a generic "greater-than" function that (a) takes two objects as arguments, each of which has a "value" method which returns an integer; and (b) returns the argument whose "value" method returns the larger integer.  Your generic function should be such that it can be compiled once and used for all clients of the function.
    2. [10 points] Write a method in an object-oriented language without generics that performs the same function as the the function in part (i). 
    3. [10 points] Discuss the relative strengths and weaknesses of your two implementations.
  4. Let's suppose you want to add subrange types to a language that has only an INTEGER type.  Moreover, you want to support strong type checking in your language. 
    1. [12 points] State what narrowing and widening conversions you will support in your language.  Be precise about your conversions.  Explain the reasons for your choices.
    2. [12 points] State what type you will use for a literal value (e.g., 7).  Explain the reasons for your choice.