WRIGHT STATE UNIVERSITY
Department of Computer Science and Engineering
CEG860 Winter 2007                               Midterm (30 pts)                                         Prasad

Please be clear, concise, and complete while answering the following questions. Unnecessary (especially incorrect) information will be penalized. Substantiate your claims, and whenever appropriate, cite practical examples. This exam is an open book exam.

1. Modularity (10)
The following quotation is taken from the paper titled "Uniprocessor Garbage Collection Techniques'' by Paul R. Wilson et al:

"Garbage Collection is necessary for fully modular programming, to avoid introducing unnecessary intermodular dependencies. A software routine operating on a data structure should not have to depend on what other routines may be operating on the same structure, unless there is some good reason to coordinate their activities. If objects must be deallocated explicitly, some module must be responsible for knowing when other modules are not interested in a particular object. ...
Failing to reclaim memory at the proper point may lead to slow memory leaks, with unreclaimed memory gradually accumulating until the process terminates or swap space is exhausted. Reclaiming memory too soon can lead to very strange behavior, because an object's space may be reused to store a completely different object while an old pointer still exists.''

Explain how automatic garbage collection supports decomposability, continuity, and protection criteria of modularity.

2. Reusability and Specification (4 + 6)
A set is a commonly occurring data type. Explain issues relevant to the design and implementation of  the reusable Set type. In particular, discuss the role and the benefits of object-oriented features.

Now pick an object-oriented language of your choice and write an interface specification for the reusable Set type. Critique your code with respect to what it ought to have ideally, if the language imposes "unnecessary" restrictions. (Recall that the interface decouples clients of Set from its concrete implementations.)

3. OOP Concepts (2 + 8)
Does the following Java program compile without errors? If not, find and fix the errors, before proceeding further. 
Now, trace the output of running (the potentially modified) Java program.    

    class P {
        String f(P p) { return "\t f(P) in P. \n";}
    }
    class C extends P {
        String f(P p) { return "\t f(P) in C. \n";}
        String f(C c) { return "\t f(C) in P. \n";}
    }
     class MT07 {
        public static void main(String[] args) {
            P pp  = new P();
            P pc  = new C();
            C cc  = pc;
	    System.out.print( pp.f(cc) +  pc.f(pp) +  pc.f(cc) + cc.f(pc) );
        }
    }

T. K. Prasad