私有化外部方法访问
public class outer {
//外部定义的方法
private class student {
public void play() {
System.out.println(“只有学生才会喜欢打篮球”);
}
}
public void teacher() {
student stu = new student();
stu.play();
}
public static void main(String[] args) {
outer s = new outer();
s.teacher();
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190829160733358.png)
}