CSC 224

Winter 2003

Sample final questions

  1. Write a method called writeArrayToFile that takes an integer array parameter A and a String parameter outputFileName and that writes the integers in the array out to the file named by outputFileName.   The file must be opened before being written to.  Suggestion: Use a BufferedWriter object for the file.
  2. Why would a class implement the Comparable interface?
  3. Why would a class implement the Serializable interface?
  4. What makes an exception a checked exception?
  5. Write a definition for a Queue class that extends one of the Java Collection classes.  A queue is a linear data structure that permits items to be added to its end and removed from its front. 
  6. Using the box-and-pointer notation, illustrate the state of memory after the execution of the following statements, where IntMatrix is the class defined on the Codes page in the zip file Matrix.zip.  Make sure to include memory allocated to instance variables.
    IntMatrix M = new IntMatrix(3,4);
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 4; j++) {  
        M.setIntValue(i*j, i, j);
      }
    }