Test测试类代码:
package com.proj;
public class Test {
public static void main(String[] args) {
// 成员内部类测试
BallTest.Inner_m test1 = new BallTest().new Inner_m();
test1.play();
// 方法类测试
BallTest b2 = new BallTest();
Ball ball = b2.info();
ball.play();
// 匿名内部类测试
BallTest three = new BallTest();
three.playBall(new Ball() {
public void play() {
System.out.println("***************");
System.out.println("匿名内部类:");
System.out.println("打排球");
}
});
}
}
Ball接口代码:
package com.proj;
public interface Ball {
// 创建抽象类方法,此处的abstract可以不写,接口中默认自带的
abstract void play();
}