public class Study {
class chinese{
{
System.out.println("out name:="+Study.this.name);//如果内部类的成员变量与外部重复,访问外部类的成员变量时需要用(类名.this.变量名)来访问
System.out.println("inner name:="+name);
}
}
public static void main(String[] args) {
Study study=new Study();
chinese c=study.new chinese();//实例化内部类的方法
c.show();
}
}
String name="Hello";
void study()
{
System.out.println("inner name:="+name);//外部类不能直接访问内部类的变量和方法
show();//这样写是错误的
}
class chinese{
String name="chineae";
{
System.out.println("out name:="+Study.this.name);//如果内部类的成员变量与外部重复,访问外部类的成员变量时需要用(类名.this.变量名)来访问
System.out.println("inner name:="+name);
}
}
public static void main(String[] args) {
Study study=new Study();
chinese c=study.new chinese();//实例化内部类的方法
c.show();
}
}