I have three questions.
1- How can non-final fields be used in a anonymous class class if their value can change?
class Foo{
private int i;
void bar(){
i = 10
Runnable runnable = new Runnable (){
public void run (){
System.out.println(i); //works fine
}//end method run
}//end Runnable
}//end method bar
}//end class Foo
2- Why static nested classes can't be declared inside methods as inner classes can uner the name of (local classes)?
Class Foo {
void bar(){
class LocalClass{ //static nested classes are NOT allowed here
//define members
}//end class LocalClass
}//end method bar
}//end class Foo
3- Why can't an inner class define static members except static final fields?
class Foo {
class Bar{
static int x; //NOTallowed
static final int y; //allowed
static void doSomething(){} //NOT allowed
}//end class Bar
}//end class Foo
For the third question, I know that inner classes are associated with instances of their outer classes, but this is still not convincing answer for me. We could just use somthing like new Foo().Bar.doSomething();
if static methods were allowed.