内部类
class StaticOuter {
private int a = 1;
private static int b = 2;
public static void test() {
System.out.println("Outer static test ...");
}
public void test2(){
System.out.println("Outer instabce test ...");
}
static class StaticInner {
public int a = 200;
static int b =300;
public static void test(){
System.out.println("Inner static test ...");
}
public void test2(){
System.out.println("Inner instance test ...");
StaticOuter.test();
new StaticOuter().test2();
System.out.println("StaticOuter.b = "+StaticOuter.b);
}
}
}
class MemberOuter{
private String s1 = "Outer InstanceMar";
private String s2 = "OuterStatic s2";
public void setS1(String s1) {
this.s1 = s1;
new MemberOuter().new MemberInner();
this.new MemberInner();
}
class MemberInner{
String s1= "Inner instanceMae ";
static final String s4 = "static final MemberInner";
void test2() {
System.out.println("s2 = "+s2);
}
}
}
interface Action {
public void do();
}
class Person {
public void user(Action pen) {
pen.do();
}
}
public class AnyInnerClass {
public static void main(String args[]) {
Person p = new Person();
p.user(new Pen() {
@Override
public void write() {
}
});
}
}
网友评论