class TD
{
int y = 6;
static class Inner //内部类,静态的
{
static int y = 3;
void show()
{
System.out.println(y);
}
}
}
class TC
{
public static void main(String[] args)
{
TD.Inner ti = new TD().new Inner();//这样建立对象是错的,why?
//怎么建立一个新对象??
ti.show();
}
}
静态内部类就具备static的特性,也就是说静态内部类中的成员必须都是静态的,都是静态的还有必要创建对象吗?
所以可以这样访问new TD.Inner().show();
class TC
{
public static void main(String[] args)
{
//TD.Inner ti = new TD().new Inner();//这样建立对象是错的,why?
new TD.Inner().show(); //怎么建立一个新对象??
//ti.show();
}
}希望能帮到你