方法内部类就是在外部类的成员方法中的类
public class Outer2 {
private String a="张三"; //外部类成员属性
//外部类的方法
public void show(){
//方法内部类不能在外部方法以外的地方用
// 所以不能用访问控制符和static修饰
class Inner{
int score=80;
public void test(){
System.out.println(a+"成绩为:"+score);
}
}
//实例化方法内部类
Inner inner=new Inner();
//调用方法内部类中的方法
inner.test();
}
public static void main(String[] args) {
Outer2 outer2=new Outer2();
outer2.show();
}
}
要点和解释都在注释里,也希望养成习惯写注释,加油