Ryerson University
School of Computer Science
CPS209 Term Test #1(C) : Winter 2006
Worth = 15%; Time limit = 50 minutes; No aids

Name:____________________________________ Student #: ______________________

Section #: ______________________
Note: there are several meanings of the word interface, but in this exam the only meaning that applies is the java construct of which Comparable is a typical example.
A. (1 point each)
  1. Polymorphism. Consider the call x.getMeasure() in the DataSet class that we studied as an example, where x is of type Measurable, an interface.
  2. Inner class. List two kinds of variables that an inner class can access from the outer class.
  3. Interface. Suppose classes A and B implement interface X and Y. Indicate whether each of the following blocks considered in isolation will (a) work without error, (b) have a compilation error or (c) have a runtime error.
  4. Inner class: Give two reasons why one might write a class as an inner class rather than a top-level class?
  5. drawing: Write a panel's paintComponent which draws a blue line from the top left corner of the panel to the bottom right corner (even if the panel is resized).
              public void paintComponent(Graphics g)
                  Graphics2D g2 = (Graphics) g ;

B. (5 points) Write a static method which returns true if the array parameter x refers to an array of objects already sorted in ascending (increasing) order; otherwise it returns false. Make the method depend on the interface Comparable.

C. (5 points) Write a class which could be used to make a listener object for a JButton. The constructor receives a reference to a BankAccount object as a parameter. Every second press of the button have the listener deposit 100 to the bank account, and every other press withdraw 50.