Java Reference
In-Depth Information
1 class Outer
2 {
3 private int x = 0;
4 private static int y = 37;
5
6 private class Inner1 implements SomeInterface
7 {
8 private int a = x + y;
9 }
10
11 private static class Inner2 implements SomeInterface
12 {
13 private int b = x + y;
14 }
15 }
figure 15.17
Code for Exercises
15.3 and 15.4
In Figure 15.17 (assuming illegal code is fixed), how are objects of
type Inner1 and Inner2 created (you may suggest additional members)?
15.4
What is a StringBuilder ?
15.5
IN THEORY
15.6
Suppose an inner class I is declared public in its outer class O . Why
might unusual syntax be required to declare a class E that extends I but
is declared as a top-level class? (The required syntax is even more
bizarre than what was seen for new , but often requires bad design to be
needed.)
What is the running time of clear , as implemented for ArrayList ?
What would be the running time if the inherited version from
AbstractCollection was used instead?
15.7
IN PRACTICE
15.8
Add both the previous and hasPrevious methods to the final version of
the MyContainer class.
Assume that we would like an iterator that implements the isValid ,
advance , and retrieve set of methods, but all we have is the standard
java.util.Iterator interface.
a.
15.9
What pattern describes the problem we are trying to solve?
b.
Design a BetterIterator class, and then implement it in terms of
java.util.Iterator .
Search WWH ::




Custom Search