Pop quiz 1 (morning section) with answers

  1. What three words do the initials ``ADT'' stand for? Abstract Data Type
  2. Express in big-O notation the time n^2 + n^3 + n log n + 2: O(n^3)
  3. I have defined a class MyClass and a variable x as follows:
    public class MyClass {
      private int z;
      public void meth (int v) {
        z = v;
      }
    }
     ...
    MyClass x = null;
    x.meth (3);
    
    What happens when I execute the last statement, x.meth (3)?

    What happens is that x has the value null, so we cannot access x.meth, and instead Java throws a NullPointerException.

  4. Show the import statement needed to use the package stored in the directory a/big/code/directory.
    import a.big.code.directory;
    
  5. What is the difference, if any, between using == for equality comparison and using the equals method of a class? Assume the class does not implement its own equals method, i.e. the default equals method is used.

    The default equals method returns exactly the same result as == (see p. 76 in the book).