内部类
成员内部类
public class Outer{
public void id(){
System.out.println("这是外部类方法");
}
public class Inner{
public void id(){
System.out.println("这是内部类方法");
}
}
public static void main (String[] args){
Outer outer =new Outer();
Outer.Inner inner =outer.new Inner();// 获得内部类
inner.id();
}
}
静态内部类
public class Outer{
public void id(){
System.out.Println("这是外部类方法");
}
public static class Inner{
public void id(){
System.out.println("这是内部类方法");
}
}
public static void main(String[] args) {
Outer outer =new Outer();
outer.id();
Outer.Inner inner =new Inner();
inner.id();
}
}
局部内部类