区别:
静态内部类相对与外部类是独立存在的,在静态内部类中无法直接访问外部类中变量、方法。如果要访问的话,必须要new一个外部类的对象,使用new出来的对象来访问。但是可以直接访问静态的变量、调用静态的方法;
普通内部类作为外部类一个成员而存在,在普通内部类中可以直接访问外部类属性,调用外部类的方法。
外部类访问方式:
public class test {
int c=1;
static class hah
{
int a=1;
public int get_a()
{
int d=new test().c;
return a+d;
}
}
class heh
{
int b =1;
public int get_b()
{
return b;
}
}
}
public class robt {
public static void main(String [] args)
{
//静态内部类直接new
test.hah h=new test.hah();
int c=h.get_a();
//非静态内部类要通过自身外部类的类明调用
test.heh d=new test().new heh();
}
}