interface product{
void price();
}
public class test1 {
private int i=1;
private String ts="test1";
private class shoe implements product{
public void price(){
System.out.println("i am excuted at "+ts+" innerclass!");
test();//内部类可以访问类的成员和方法
}
}
public shoe getshoe(){
return new shoe();
}
private void test(){
System.out.println(i);
}
public static void main(String[] args){
test1 t=new test1();
product p=t.getshoe();
test1.shoe s=t.new shoe();
s.price();
p.price();
}
}
用内部类,可以完全隐藏实现细节。[color=red]某个类的内部类和其成员,方法具有同等的权利[/color]
内部类如果要调用传入的参数时则需将传入的参数设置为[color=red]final[/color]