test.getplay 方法有错
public class Test {
public static void main(String[] args) {
//完成成员内部类内部测试
BallTest.Inner_m one=new BallTest().new Inner_m();
one.play();
//方法内部类
BallTest two=new BallTest();
two.info();
Test test = new Test();
test.play(new Ball() {
public void play() {
System.out.println("**************");
System.out.println("打排球");
}
});
}
}
public interface Ball {
public abstract void play();
}
public class BallTest {
public BallTest() {
}
public class Inner_m implements Ball {
@Override
public void play() {
System.out.println("成员内部类");
System.out.println("打篮球");
}
}
public void info() {
class Inner_f implements Ball{
@Override
public void play() {
// TODO Auto-generated method stub
System.out.println("方法内部类");
System.out.println("打乒乓球");
}
}
new Inner_f().play();
}
public void playBall(Ball ball) {
ball.play();
}
}
正在回答 回答被采纳积分+1
同学你好,同学尝试使用BallTest类的引用调用playBall()方法。修改后代码如下:

public class Test {
public static void main(String[] args) {
//完成成员内部类内部测试
BallTest.Inner_m one=new BallTest().new Inner_m();
one.play();
//方法内部类
BallTest two=new BallTest();
two.info();
two.playBall(new Ball() {
public void play() {
System.out.println("**************");
System.out.println("打排球");
}
});
}
}如果我的回答解决了你的疑惑,请采纳,祝学习愉快~
- 参与学习 人
- 提交作业 3802 份
- 解答问题 11489 个
本阶段带你迈入Java世界,学习Java必备基础知识,基础语法、面向对象思想以及常用工具类的使用。
了解课程

恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星