Programming Languages questions ------------------------------- 1. In addition to regular top-level class declarations, Java supports various flavors of "inner classes:" classes declared within other classes. One flavor, called an anonymous inner class, allows a method to declare and instantiate a class all in one statement: public Object getNewObject() { final int i = 3; Object o = new Object { public int getInt() { return i; } }; return o; } (a) How do you suppose the anonymous inner classs mechanism is implemented, in terms of the activation record stack, control and access links? (b) Should C++ be extended to support a similar mechanism? Why or why not? (c) In the example above, removing the "final" from the declaration of variable i causes a compiler error. Why might this be the case? Does it change your answer to part (a)? 2. In Java, collection classes such as queues and stacks all store references to objects derived from the Object class, allowing any object to be stored. In the C++ Standard Library a similar effect is achieved by instantiating collection classes from class templates. What are the relative advantages of the two approaches? 3. Inheritance has been described as just a specialized from of composition. In other words, rather than deriving class D from class B, you could include an instance of class B as a member of D. What is the main advantage of providing inheritance as part of the language? What is the main advantage of composition compared with inheritance?