<pre>
class Counter{
public static void main(
String[] args){
Thread t = new Thread(new CounterBehavior());
t.start();
}
}
</pre>
Which of the following is a valid definition of CounterBehavior that would make Counter�s main() method count from 1 to 100, counting once per second?
b) This class is an inner class to Counter:
<pre>
class CounterBehavior implements Runnable {
public void run() {
for (int i = 1; i <= 100; i++);
try {
System.out.println(i);
Thread.sleep(1000);
} catch (InterruptedException x) {}
}
}
}
</pre>
this answer is wrong for the reason "b is not correct because the inner class is needed in main(), where there is no instance of the enclosing class (Counter)."
I'm confused on the access rules here. Do you have to instantiate an outer class, to reach an inner class, even from within the class? And if so, is it always or just for static methods? (My thinking is, you can have a custom adapter class, for example, and instantiate that from a method, without instantiating the outer class, so why doesn't this work? You can ignore these parentheses if they constitute a second question
)
Thank You
Eric