aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Quiz on anonymous classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Quiz on anonymous classes" Watch "Quiz on anonymous classes" New topic
Author

Quiz on anonymous classes

Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
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

Joined: Mar 05, 2003
Posts: 1391
Hint:
Here is an analysis of the class structures and relationships.

[ August 14, 2003: Message edited by: Marlene Miller ]
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
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

Joined: Mar 05, 2003
Posts: 1391
Answer: Part II.
The new classes have the same structure as the old classes.

My way of viewing the heap.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Quiz on anonymous classes