I was reading the articles regarding the inner classes and out of curiosity I declared the static members within the inner class. Strangely no compile time error was shown and the code just executed fine.
I referred back the oracle documents and could still found the statement : 'because an inner class is associated with an instance, it cannot define any static members itself.'
I am really confused, if there is an enhancement to the inner classes done with the later versions of java where we can now declare the static members within the inner classes as well?
Any light on that will be appreciated.
Here is the code snippet you may try with Java 17:
class Outer{
class Inner{
static int i =10;
public static void method(){
System.out.println("The static members can be now declared within Inner classes!!!!");
}
}
}