class TD
{
int y = 6;
static class Inner
{
static int y = 3;
static void show()
{
System.out.println(y);
}
}
}
/*
当内部类被static修饰后,其他外部要访问静态内部类的静态成员,其实就是直接通过类名调用:TD.Inner.show();
*/
class TD1
{
int y = 6;
static class Inner
{
static int y = 3;
void show()
{
System.out.println(y);
}
}
}
class P1
{
public static void main(String[] args)
{
TD.Inner.show();
new TD1.Inner().show();
}
}
result:
3
3
/*
当内部类被static修饰后,其他外部要访问静态内部类的非静态成员,是通过内部类的对象访问的:
new TD1.Inner().show();
*/ |