about enthuware.ocpjp.v7.2.1480
Posted: Wed Jun 07, 2017 5:37 am
public class TestClass
{
static int si = 10; int ii = 20;
public static void inner()
{
int ai = 30; //automatic variable
final int fai = 40; //automatic final variable
class Inner
{
public Inner() { System.out.println(si+" "+fai+" "+ai);
}
}
new Inner();
}
public static void main(String[] args) { TestClass.inner(); }
}
The explanation tells me that "ai" can't be acessed. But when I tested it Inner class was able to access ai.
Can you please elaborate why you have mentioned "ai can't be accessed"?
{
static int si = 10; int ii = 20;
public static void inner()
{
int ai = 30; //automatic variable
final int fai = 40; //automatic final variable
class Inner
{
public Inner() { System.out.println(si+" "+fai+" "+ai);
}
}
new Inner();
}
public static void main(String[] args) { TestClass.inner(); }
}
The explanation tells me that "ai" can't be acessed. But when I tested it Inner class was able to access ai.
Can you please elaborate why you have mentioned "ai can't be accessed"?