Home CPSC 330

Essay Exam 1

Due: September 30

Directions


Questions

  1. Explain the potential problem with the following inheritance hierarchy:
    
    class Rectangle {
      public Rectangle(int l, int w) {
        length = l;
        width = w;
      }
    
      public void setLength(int l) {
        length = l;
      }
    
      public void setWidth(int w) {
        width = w;
      }
    
      private int length, width;
    }
    
    class Square extends Rectangle {
      public square(int size) {
        super(size, size);
      }
    }
    
    How could this problem be resolved?

  2. Consider the following situations that might arise when writing a Binary Search Tree class. For each one, should it be ignored, handled with an exception, or handled with an assert? Justify your answer.

  3. What are some reasons to avoid duplication in a software project?

  4. What are the differences between a class and an interface in Java?

Submitting

Submit your answers by emailing them to ifinlay@umw.edu. Please email your answers as a PDF document.

Copyright © 2018 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.