| CSC 207 | Algorithms and Object Oriented Design | Spring 2010 |
Summary: In this lab, you will reinforce the properties of Java's inner classes.
mkdir somewhere/innerclasses
cd somewhere/innerclasses
cp ~weinman/public_html/courses/CSC207/2010S/labs/code/innerclasses/Exercise1.java cp ~weinman/public_html/courses/CSC207/2010S/labs/code/innerclasses/Exercise2.java cp ~weinman/public_html/courses/CSC207/2010S/labs/code/innerclasses/Vector3D.java
public class Exercise1 {
private int i = 1;
private static int j = 42;
static class Inner {
private int x = i + j;
}
}
x legal? Why or why not?
Inner non-static?
static? static?
Exercise1.this.i somewhere in Inner1?
static similar to
other places you have seen it used (e.g. variables and methods)?
Confirm your explanation with a neighbor.
static modifier to class
Inner. Say we added the following method at line 9.
private int getX() { return x; }
public class Exercise2 {
private int i;
private static int j = 42;
public int fiddle() {
Inner1 obj = new Inner1(); // Default constructor
i = Inner1.x;
return i + j;
}
private static class Inner1 {
private static int x = 207;
}
}
i = Inner1.x;Vector3D and its inner class, which
you copied to your directory at the outset of this lab, to make
sure you understand its intended behavior.
Vector3D.java. What happens? Try to come up
with an explanation.
private class VectorIterator<AnyType2> implements Iterator<AnyType2> {
next() to resolve this
problem.
private class VectorIterator implements Iterator<AnyType> {
next() to AnyType.
VectorIterator the
way we first tried to? Be prepared to reflect on this.