COM1204 Summer 2002 -- Midterm Exam Sampler

Professor Futrelle, Northeastern U., College of Computer & Information Sciences

Version of 7/27/2002

1. Write out the class definition for an empty adapter class called LaunchAdapter for the following interface:

interface Launch {
  Date schedule(Date firstPossible);
  void setFuelingTime(DateTime theTime);
  }

Then write the declaration line for a class definition that subclasses the adapter.

2. Write a simple class definition that has a method that can return an instance of the class, but does not allow the use of new directly.

3. The abstract class Planet has two subclasses, Habitable and Harsh. Write the following snippets:

  1. Constructors for each, that set prob to 0.9 and 0.1.respectively
  2. Field prob and method GetProbabilityOfLife() in Planet that returns prob.
  3. Creation of a Harsh instance and assignment to variable of type Planet.
  4. Call of GetProbabilityOfLife() on the instance.

Explain, in Object-Oriented terminology, what value this last call returns and why.

4.Write a trivial factory method that returns an instance of a subclass chosen from two subclasses of a class. You needn't define any of the classes, just the method declaration with a body. Make up your own, easy-to-understand names for the classes.

5.Explain the difference between simple overloading and the more object-oriented concept of overriding. Do this in the following way:

  1. For a class ClassOne, show how overloading can occur even within a single class definition. Define two such methods, exampleMeth(), with no bodies.
  2. For a subclass, ClassOneOne, show how exampleMeth() could be overridden (not overloaded).
  3. Using the correct OO terminology, explain how the appropriate code to execute is chosen for the overridden method. Is this done at compile time or run time, and how and why?

6. NOT COVERED ON THE MIDTERM: The data and functionality that are associated with a class is different than that associated with class instances. Illustrate this for class-related aspects by writing a definition of a class-related procedure that returns the value of the int variable val. Write a tiny main() function that calls this procedure and prints the value returned to standard out. Explain, using proper OO terminology, what is going on.

7. The data and functionality that are associated with a class instance is different than that associated with a class per se. Illustrate this for object-related aspects by writing a definition of a method that returns the value of the int variable val. Write a tiny main() function that calls this method and prints the value returned to standard out. Explain, using proper OO terminology, what is going on.

8. Assume that B is a subclass of A, aMeth() is defined in A and bMeth() is defined only in B. Explain, using proper OO terminology, which of the following are legal, which are illegal, and why.


Return to the COM1204 home page