CSE116B Quiz 1 9/27/05 Name : Person Number : 1. Consider the following piece of code : public class foo { int a = 2; Bag b = new Bag(); public void bar{ int c = 4; Bag d = new Bag(); } } Where is storage allocated for a, b, c, and d, respectively? ANSWER : a, b, and d are on the heap. c is on the stack. See slide #36 in the powerpoint presentation on Memory. 2. What is the primary difference between the Set and the Bag ADTs? ANSWER : Bags allow duplicates, Sets do not. See slide #2 in the sets powerpoint. 3. In my example for both the Set and Bag ADTs, what was the benefit of creating a Factory class to return Set and Bag objects? ANSWER : The factory class allows the client code to obtain an instance of a set (in the case of SetFactory) or a bag (in the case of BagFactory) without knowing what actual concrete implementation is being used. This allows you to change the concrete implementation, returning a more efficient or stable or improved implementation (think extendable vs. simple set) without needing to change the client code. This is potentially very useful if you had used the bag or set interface in many pieces of client code, because you need only make one change (to the factory) rather than many changes (to each client class that uses a set).