Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Quiz on anonymous classes

 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a quiz based on K&B Chapter 8, Self Test 12, page 485-486
This is a lean version of the example.

Quiz: Replace the anonymous class declarations with named class declarations and instantiate the classes. Try to preserve the class structures and relationships.
For example,
class C extends A {}
A x = new C();
[ August 14, 2003: Message edited by: Marlene Miller ]
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint:
Here is an analysis of the class structures and relationships.

[ August 14, 2003: Message edited by: Marlene Miller ]
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer: Part I.

In the first example, the anonymous subclass of A.B is an inner class of A. The reference to the enclosing instance is passed upstairs through the constructor of the anonymous class. The subclass is instantiated in a static context. It does not need the reference itself. That is difficult for me to understand.
[ August 14, 2003: Message edited by: Marlene Miller ]
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer: Part II.
The new classes have the same structure as the old classes.

My way of viewing the heap.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic